Import a hand-built environment until the plan is empty

applied · 70 min · Objective 2.2

Task

Adopt an existing estate into code the safe way. The discipline is step three: import, then plan, and keep adjusting the code until the plan is EMPTY -- because applying a non-empty plan after an import modifies the live resource you were only trying to document.

Steps

  1. By hand, outside any tool, create a small environment: a network, two containers with specific labels and settings, and a volume. Record what you created in lab/existing.md.
  2. Write declarations matching them as accurately as you can from inspection, not from memory of what you typed.
  3. Import each resource into state. After EACH import, run plan and record the output in lab/import-log.txt.
  4. Adjust the code until plan is empty for every resource. Record each discrepancy you had to fix -- these are the attributes you did not know the resource had.
  5. Prove the adoption: destroy everything through the tool, re-apply from code, and confirm the rebuilt environment matches lab/existing.md.

Verify

grep -Eci 'import' lab/import-log.txt
grep -Ec 'no changes|0 to add, 0 to change, 0 to destroy|empty' lab/import-log.txt
grep -c '^' lab/existing.md

The log must end with an empty plan. An import that was never driven to an empty plan has recorded a mapping and left the code disagreeing with reality, which is worse than not importing at all.

Notes

This environment is disposable and holds nothing you want to keep, which is what makes the destroy-and-rebuild proof in step 5 safe to run.

This is an independent study companion for CompTIA Cloud+ CV0-004 and is not produced by or endorsed by CompTIA.