Recover from a partial deployment without making it worse
Task
Make a deployment fail halfway, leaving some resources created and some not, then recover it correctly. This is where people make things worse, usually by fixing something manually and leaving state disagreeing with reality.
Steps
- Write a stack of six resources where the fifth will fail -- an invalid value, or a quota you have deliberately lowered. Apply it and record what exists afterwards and what the tool's state believes, in
lab/tshoot/partial.md. - Compare the two lists explicitly. Record any resource that exists and is NOT in state -- an orphan the tool cannot see.
- Recover the correct way: fix the cause, re-apply, and confirm the tool created only what was missing. Record that the re-run was safe because the template is idempotent.
- Now create the harder case: destroy one resource BY HAND, then re-apply without telling the tool. Record what the plan proposed and whether it matched what you expected.
- Finally, create an orphan deliberately -- a resource matching the template's naming but created outside it -- and record the collision error on the next apply, then resolve it by importing rather than deleting.
Verify
grep -Eci 'orphan|not in state' lab/tshoot/partial.md
grep -Eci 'idempotent|re-?ran|re-?apply' lab/tshoot/partial.md
grep -Eci 'collision|already exists' lab/tshoot/partial.md
grep -Eci 'import' lab/tshoot/partial.md
All four non-zero. The orphan is the important artefact: a resource created outside state is invisible to drift detection and announces itself only as a name collision later.
This is an independent study companion for CompTIA Cloud+ CV0-004 and is not produced by or endorsed by CompTIA.