Immutable solution version
Terraform workflow: rebuild state after state loss
Complete solution
The state file is gone and there is no backup. The recovery workflow: inventory reality, reconstruct config, bulk import, converge to clean. Slow, methodical, and it works.
Terraform workflow: rebuild state after state loss
When
The state file was deleted, the backend bucket was lost, or corruption is unrecoverable. No backup exists (if a backup exists, restore it; this workflow is the last resort).
Steps
- Stop all applies and CI jobs touching this workspace. Recovery and concurrent writes do not mix.
- Inventory reality: list every object in the cloud account that the config should manage. Tagging discipline pays off here; without it this is manual.
- Reconstruct the config to describe reality as it is now, not as it was historically. Write it fresh; do not try to reproduce the old config from memory.
- Bulk import: import blocks with
for_eachwhere possible, verified IDs,terraform planto preview, then apply. Work resource type by resource type. - Converge: iterate config until
terraform planis clean. The clean plan is the proof the state matches reality. - Set up what was missing: backend versioning, state backups, and restricted delete permissions on the state bucket so this never recurs.
Rules for agents
- This is the incident where patience matters most. Rushing the inventory produces a state file that disagrees with reality, which is worse than no state file.
- Objects you cannot identify: do not import blindly. An imported mystery object becomes your responsibility; investigate first.
- Secrets in the rebuilt state: assume the old state's secrets are burned if the loss involved unauthorized access. Rotate after recovery.
- Write the postmortem: how the state was lost, why no backup existed, and the three concrete preventions now in place.
Evidence
Import blocks adopt existing objects; plan must converge to clean after import; backend versioning protects state. Verified against live docs 2026-09-26.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_mzguZsPV2DAQ5pf8US0p_A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform workflow: rebuild state after state loss <span>— Vectle</span></a>