-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreference.html
More file actions
517 lines (468 loc) · 21.1 KB
/
Copy pathreference.html
File metadata and controls
517 lines (468 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Reference | CloudtoRepo</title>
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- NAV -->
<nav>
<a class="nav-logo" href="index.html"><span>Cloud</span>toRepo</a>
<div class="nav-links">
<a href="index.html" class="hide-sm">← cloudtorepo.com</a>
<a class="btn-gh" href="https://github.com/andrewbakercloudscale/cloudtorepo" target="_blank" rel="noopener">
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
GitHub
</a>
</div>
</nav>
<!-- PAGE HERO -->
<div class="page-hero">
<div class="page-hero-label">Commands & output</div>
<h1>Full command reference</h1>
<p>Complete reference for all six CloudtoRepo tools: the output file structure, drift detection, reconcile coverage scoring, one-command Markdown reports, the run automation wrapper, and the import state helper.</p>
</div>
<!-- OUTPUT -->
<hr class="divider" />
<section id="output">
<div class="section-label">Output</div>
<h2>Clean, structured Terraform files</h2>
<p class="section-intro">Each service gets its own directory with three files that Terraform can use immediately.</p>
<div class="output-grid">
<div class="output-card reveal">
<h3>imports.tf</h3>
<p>One <code>import {}</code> block per discovered resource.</p>
<pre><span class="kw">import</span> {
to = aws_eks_cluster.<span class="str">cluster_production</span>
id = <span class="str">"production"</span>
}
<span class="kw">import</span> {
to = aws_rds_instance.<span class="str">db_primary</span>
id = <span class="str">"prod-postgres-01"</span>
}</pre>
</div>
<div class="output-card reveal">
<h3>backend.tf</h3>
<p>S3 remote state configuration and AWS provider block, ready to init.</p>
<pre><span class="kw">terraform</span> {
backend <span class="str">"s3"</span> {
bucket = <span class="str">"my-tf-state"</span>
key = <span class="str">"us-east-1/eks/terraform.tfstate"</span>
region = <span class="str">"us-east-1"</span>
}
}</pre>
</div>
<div class="output-card reveal">
<h3>resources.tf</h3>
<p>Empty resource skeletons matching every import block, populated by <code>terraform plan -generate-config-out</code>.</p>
<pre><span class="kw">resource</span> <span class="str">"aws_eks_cluster"</span> <span class="str">"cluster_production"</span> {
<span class="cm"># populated by terraform plan</span>
<span class="cm"># -generate-config-out=generated.tf</span>
}</pre>
</div>
<div class="output-card reveal">
<h3>Directory structure</h3>
<p>Organised by account → region → service for easy navigation.</p>
<pre>tf-output/
├── summary.txt
└── 123456789012/
├── us-east-1/
│ ├── ec2/
│ ├── eks/
│ └── rds/
└── eu-west-1/</pre>
</div>
</div>
</section>
<!-- DRIFT -->
<hr class="divider" />
<section id="drift">
<div class="section-label">Drift detection</div>
<h2>Stay in sync after day one</h2>
<p class="section-intro">
Once your Terraform baseline is committed, <code>drift.sh</code> re-scans AWS and
diffs the results against your <code>imports.tf</code> files with no AWS Resource Explorer required.
</p>
<div class="steps">
<div class="step reveal">
<div class="step-num">NEW</div>
<h3>Resources added outside Terraform</h3>
<p>Found in AWS but missing from <code>imports.tf</code>. With <code>--apply</code>, new <code>import {}</code> blocks are appended automatically.</p>
</div>
<div class="step reveal">
<div class="step-num">REMOVED</div>
<h3>Resources deleted outside Terraform</h3>
<p>Present in <code>imports.tf</code> but no longer in AWS. With <code>--apply</code>, stale blocks are commented out with a timestamp.</p>
</div>
<div class="step reveal">
<div class="step-num">CI</div>
<h3>Run on a schedule</h3>
<p>Drop <code>drift.sh</code> into a nightly CI job. Pass <code>--report ./drift.txt</code> to save output, then feed it into <code>report.sh</code> to generate a Markdown summary.</p>
</div>
</div>
<div style="margin-top:2rem;">
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">Sample drift report</h3>
<pre><span class="cm"># report only</span>
./drift.sh --output ./tf-output --regions <span class="str">"us-east-1"</span>
<span class="cm"># apply changes to imports.tf</span>
./drift.sh --output ./tf-output --regions <span class="str">"us-east-1"</span> --apply
<span class="cm">-------------------------------------------------------</span>
<span class="kw">NEW</span> (2 resource(s) found in AWS, not in imports.tf)
+ aws_instance.web_server_new (id: i-0abc123def456)
+ aws_instance.batch_worker (id: i-0def789abc012)
<span class="kw">REMOVED</span> (1 resource(s) in imports.tf, no longer in AWS)
- aws_instance.old_bastion (id: i-0111222333444)
<span class="cm">-------------------------------------------------------</span>
Unchanged: 22
New (not yet imported): 2
Removed (stale): 1</pre>
</div>
</div>
</section>
<!-- RECONCILE -->
<hr class="divider" />
<section id="reconcile">
<div class="section-label">Coverage check</div>
<h2>Find what you missed</h2>
<p class="section-intro">
After exporting, <code>reconcile.sh</code> cross-references your <code>imports.tf</code>
files against AWS Resource Explorer to surface any resources that were skipped.
No Resource Explorer? Use <code>--local</code> for an instant per-service summary from
the output directory alone.
</p>
<div class="steps">
<div class="step reveal">
<div class="step-num">%</div>
<h3>Coverage score</h3>
<p>Compares every import ID against all ARNs returned by Resource Explorer. Reports matched, missed, and overall coverage percentage.</p>
</div>
<div class="step reveal">
<div class="step-num">LOCAL</div>
<h3>No Resource Explorer needed</h3>
<p><code>--local</code> skips the API call entirely and prints import block counts per account / region / service straight from the output directory. Useful during initial setup.</p>
</div>
<div class="step reveal">
<div class="step-num">LIST</div>
<h3>Discover supported services</h3>
<p>Run <code>./cloudtorepo.sh --services list</code> or <code>./drift.sh --services list</code> to print all supported service names, useful for scripting or building a custom <code>--services</code> argument.</p>
</div>
</div>
<div style="margin-top:2rem;display:flex;flex-direction:column;gap:1rem;">
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">reconcile.sh: with Resource Explorer</h3>
<pre><span class="cm"># full coverage check (requires Resource Explorer aggregator index)</span>
./reconcile.sh --output ./tf-output --index-region us-east-1
Summary
-------
Total resources (Resource Explorer): 847
Matched to exported import blocks: 801
Potentially missed: 46
Coverage: 94%</pre>
</div>
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">reconcile.sh --local: no Resource Explorer required</h3>
<pre><span class="cm"># local summary, no AWS API calls beyond listing the output directory</span>
./reconcile.sh --output ./tf-output --local
Account / Region / Service Import blocks
------------------------------------------
123456789012 / us-east-1 / ec2 47
123456789012 / us-east-1 / eks 12
123456789012 / us-east-1 / rds 8
123456789012 / us-east-1 / s3 5
123456789012 / eu-west-1 / ec2 31
------------------------------------------
Total 103
<span class="cm">Tip: enable Resource Explorer for full coverage scoring:</span>
<span class="cm"> aws resource-explorer-2 create-index --type AGGREGATOR --region us-east-1</span></pre>
</div>
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">--services list: discover all supported services</h3>
<pre><span class="cm"># print every supported service name, one per line</span>
./cloudtorepo.sh --services list
acm
apigateway
appconfig
apprunner
athena
backup
bedrock
cloudfront
cloudtrail
cloudwatch
codebuild
codepipeline
cognito
config
connect
documentdb
dynamodb
ebs
ecr
ecs
eks
elasticache
elb
emr
...and more</pre>
</div>
</div>
</section>
<!-- REPORT -->
<hr class="divider" />
<section id="report">
<div class="section-label">Reporting</div>
<h2>One-command Markdown reports</h2>
<p class="section-intro">
<code>report.sh</code> reads any <code>cloudtorepo.sh</code> output directory and generates a clean Markdown document: service breakdown, import counts, and an optional drift section from a <code>drift.sh --report</code> file.
</p>
<div class="steps">
<div class="step reveal">
<div class="step-num">MD</div>
<h3>Markdown output</h3>
<p>Write to stdout or pass <code>--out report.md</code>. Paste it into a PR description, Confluence, or a GitHub wiki. It renders instantly.</p>
</div>
<div class="step reveal">
<div class="step-num">DRIFT</div>
<h3>Drift section included</h3>
<p>Pass <code>--drift ./drift.txt</code> (produced by <code>drift.sh --report</code>) to append a NEW / REMOVED breakdown to the same document.</p>
</div>
<div class="step reveal">
<div class="step-num">CI</div>
<h3>Commit it to git</h3>
<p>Run <code>report.sh</code> at the end of every nightly drift job and commit <code>report.md</code> to a <code>infra-reports</code> branch: instant audit trail with no extra tooling.</p>
</div>
</div>
<div style="margin-top:2rem;">
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">Usage</h3>
<pre><span class="cm"># basic: prints to stdout</span>
./report.sh --output ./tf-output
<span class="cm"># with drift section, write to file</span>
./drift.sh --output ./tf-output --report ./drift.txt
./report.sh --output ./tf-output \
--drift ./drift.txt \
--title <span class="str">"Production AWS Report, March 2026"</span> \
--out report.md</pre>
</div>
</div>
<div style="margin-top:1.5rem;">
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">Example report output: account 987267051295 / af-south-1</h3>
<pre><span class="kw"># Production AWS Report, March 2026</span>
<span class="cm">**Generated:** 2026-03-25T11:06:09Z</span>
<span class="cm">**Output directory:** `./tf-output`</span>
---
<span class="kw">## Summary</span>
| | |
|---|---|
| <span class="str">**Account(s)**</span> | `987267051295` |
| <span class="str">**Region(s)**</span> | af-south-1 |
| <span class="str">**Total import blocks**</span> | <span class="kw">**366**</span> |
<span class="kw">## Resources by Service</span>
### 987267051295 / af-south-1
| Service | Import blocks |
|---------|--------------|
| `config` | 319 |
| `kms` | 9 |
| `vpc` | 9 |
| `sns` | 8 |
| `eventbridge` | 4 |
| `lambda` | 4 |
| `ebs` | 3 |
| `s3` | 3 |
| `ec2` | 2 |
| `servicecatalog`| 2 |
| `acm` | 1 |
| `backup` | 1 |
| `sqs` | 1 |
<span class="kw">## Account Totals</span>
| Account | Import blocks |
|---------|--------------|
| `987267051295` | 366 |
| `123456789012` | 219 |
<span class="kw">## Cross-Account Service Totals</span>
| Service | Import blocks |
|---------|--------------|
| `config` | 412 |
| `vpc` | 89 |
| `ec2` | 41 |
| `kms` | 18 |
| `lambda` | 12 |
---
<span class="kw">## Drift Report</span>
| Status | Count |
|--------|-------|
| Unchanged | 358 |
| New (not yet imported) | 0 |
| <span class="kw">Removed (stale)</span> | <span class="kw">8</span> |
<span class="cm">### 987267051295 / af-south-1 / vpc</span>
<span class="kw">**REMOVED (8 resource(s) in imports.tf, no longer in AWS)**</span>
- `- aws_subnet.defaultvpcsubnetb (id: subnet-93d3d4eb)`
- `- aws_subnet.defaultvpcsubnetc (id: subnet-52557418)`
- `- aws_subnet.defaultvpcsubneta (id: subnet-b156b3d8)`
- `- aws_security_group.cloudflare_proxy (id: sg-02c2539d27ffe5a5f)`
- `- aws_security_group.launch_wizard_6 (id: sg-011a26aef17beff13)`
- `- aws_security_group.launch_wizard_7 (id: sg-024bd977787fb2789)`
- `- aws_route_table.defaultroutetable (id: rtb-6157b208)`
- `- aws_internet_gateway.defaultvpcigw (id: igw-5a56b333)`</pre>
</div>
</div>
</section>
<!-- RUN -->
<hr class="divider" />
<section id="run">
<div class="section-label">Workflow automation</div>
<h2>One command to rule them all</h2>
<p class="section-intro">
After exporting, <code>run.sh</code> automates the <code>terraform init</code> +
<code>terraform plan -generate-config-out=generated.tf</code> step across every
service directory, no more running it manually per folder.
</p>
<div class="steps">
<div class="step reveal">
<div class="step-num">AUTO</div>
<h3>Walk the entire output tree</h3>
<p>Finds every directory with an <code>imports.tf</code> and runs Terraform in it. Filter by account, region, or service to process a subset.</p>
</div>
<div class="step reveal">
<div class="step-num">×5</div>
<h3>Parallel runs</h3>
<p>Up to <code>--parallel 3</code> concurrent Terraform processes by default. Logs per directory, pass/fail/no-change summary at the end.</p>
</div>
<div class="step reveal">
<div class="step-num">FAST</div>
<h3>Parallel scans + auto-retry</h3>
<p><code>cloudtorepo.sh</code> and <code>drift.sh</code> scan up to <code>--parallel 5</code> services simultaneously. All AWS API calls automatically retry on throttling with exponential back-off.</p>
</div>
</div>
<div style="margin-top:2rem;">
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">run.sh usage</h3>
<pre><span class="cm"># process everything</span>
./run.sh --output ./tf-output
<span class="cm"># filter to specific services and region</span>
./run.sh --output ./tf-output \
--regions <span class="str">"us-east-1"</span> \
--services <span class="str">"ec2,eks,rds"</span>
<span class="cm"># preview directories without running terraform</span>
./run.sh --output ./tf-output --dry-run
<span class="cm">-------------------------------------------------------</span>
[OK] 123456789012/us-east-1/eks
[OK] 123456789012/us-east-1/rds
[no-change] 123456789012/us-east-1/s3
[FAIL] 123456789012/us-east-1/iam (see .run.log)
<span class="cm">-------------------------------------------------------</span>
Succeeded (changes written): 2
No changes: 1
Failed: 1</pre>
</div>
</div>
</section>
<!-- IMPORT -->
<hr class="divider" />
<section id="importsh">
<div class="section-label">Terraform import</div>
<h2>From import blocks to state in one command</h2>
<p class="section-intro">
After <code>run.sh</code> generates <code>generated.tf</code>, use <code>import.sh</code>
to actually call <code>terraform import</code> for every resource, skipping anything
already in state automatically.
</p>
<div class="steps">
<div class="step reveal">
<div class="step-num">SKIP</div>
<h3>State-aware</h3>
<p>Runs <code>terraform state list</code> before each import. Resources already managed are silently skipped. Safe to re-run as many times as needed.</p>
</div>
<div class="step reveal">
<div class="step-num">×N</div>
<h3>Parallel imports</h3>
<p>Pass <code>--parallel N</code> to import multiple service directories concurrently. Per-directory logs in <code>.import.log</code>, pass/fail summary at the end.</p>
</div>
<div class="step reveal">
<div class="step-num">DRY</div>
<h3>Preview first</h3>
<p><code>--dry-run</code> prints every <code>address (id: ...)</code> pair that would be imported without touching state. Use it to verify scope before committing.</p>
</div>
</div>
<div style="margin-top:2rem;">
<div class="output-card reveal" style="background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem;">
<h3 style="font-size:0.95rem;font-weight:600;margin-bottom:1rem;">import.sh usage</h3>
<pre><span class="cm"># dry run: see what would be imported</span>
./import.sh --output ./tf-output --dry-run
<span class="cm"># import everything (sequential)</span>
./import.sh --output ./tf-output
<span class="cm"># import with parallel workers + auto terraform init</span>
./import.sh --output ./tf-output --parallel 4 --init
<span class="cm">-------------------------------------------------------</span>
[INFO] Importing resources (parallel=4)...
[INFO] [123456789012/us-east-1/ec2] importing aws_instance.web (id: i-0abc123)...
[INFO] [123456789012/us-east-1/rds] importing aws_db_instance.main (id: mydb)...
[INFO] =======================================================
[INFO] Resources imported: 47
[INFO] Resources skipped: 3 (already in state)
[INFO] Resources failed: 0
[INFO] =======================================================</pre>
</div>
</div>
</section>
<!-- FOOTER -->
<hr class="divider" />
<footer>
<div>
<div class="footer-brand"><span>Cloud</span>toRepo</div>
<div class="footer-meta" style="margin-top:0.4rem;">Built by <a href="https://andrewbaker.ninja" target="_blank" rel="noopener">Andrew Baker</a> · Group CIO, Capitec Bank</div>
</div>
<div class="footer-links">
<a href="tightener.html">sg-tightener</a>
<a href="https://github.com/andrewbakercloudscale/cloudtorepo" target="_blank" rel="noopener">GitHub</a>
<a href="https://github.com/andrewbakercloudscale/cloudtorepo/blob/main/LICENSE" target="_blank" rel="noopener">MIT License</a>
<a href="https://andrewbaker.ninja/2026/03/21/reverse-engineering-your-aws-estate-into-terraform-using-cloudtorepo-org/" target="_blank" rel="noopener">Blog post</a>
<a href="https://andrewbaker.ninja" target="_blank" rel="noopener">andrewbaker.ninja</a>
<a href="https://pi2s3.com" target="_blank" rel="noopener">pi2s3.com</a>
</div>
</footer>
<script>
(function() {
var els = document.querySelectorAll('.reveal');
if (!('IntersectionObserver' in window)) {
els.forEach(function(el) { el.classList.add('visible'); });
return;
}
var io = new IntersectionObserver(function(entries) {
entries.forEach(function(e) {
if (e.isIntersecting) { e.target.classList.add('visible'); io.unobserve(e.target); }
});
}, { threshold: 0.08 });
els.forEach(function(el) { io.observe(el); });
})();
</script>
<script>
document.querySelectorAll('pre').forEach(function(pre) {
var wrap = document.createElement('div');
wrap.className = 'pre-wrap';
pre.parentNode.insertBefore(wrap, pre);
wrap.appendChild(pre);
var btn = document.createElement('button');
btn.className = 'copy-btn';
btn.textContent = 'Copy';
wrap.appendChild(btn);
btn.addEventListener('click', function() {
navigator.clipboard.writeText(pre.innerText).then(function() {
btn.textContent = 'Copied!';
btn.classList.add('copied');
setTimeout(function() {
btn.textContent = 'Copy';
btn.classList.remove('copied');
}, 2000);
});
});
});
</script>
</body>
</html>