Terraform State Recovery
Scope
Recovery guidance for lost, corrupted, or inaccessible Terraform/OpenTofu state used by ClusterForge roots.
Assumptions
- State is remote for production.
- State backend access is audited.
- Recovery is manual and must be reviewed.
Prerequisites
- Backend bucket/table access.
- Terraform/OpenTofu and
cf. - Current repository checkout.
- Cloud read access for imported resources.
Recovery Steps
- Stop all applies for the affected environment.
- Identify whether state is lost, corrupted, locked, or only inaccessible.
- Restore the backend object from versioning or backup when available.
- If state cannot be restored, rebuild it with
terraform importresource by resource. - Run
terraform plan -refresh-onlyand review drift before any apply. - Commit any import documentation or root fixes.
Validation Steps
terraform state listsucceeds.terraform planshows only expected drift.- Backend locking works.
- A second operator can read the restored state.
Rollback Steps
- Restore the previous state object version.
- Keep a copy of corrupted state for audit, but do not commit it.
- Revert root changes that were made only for recovery.
Data Loss Risks
- Incorrect imports can bind Terraform to the wrong resource.
- Corrupted state edits can cause destructive plans.
- Missing state for data-bearing resources can lead to accidental recreation.
Estimated Downtime Categories
- Backend access issue: minutes to hours.
- Versioned state restore: minutes.
- Full import rebuild: hours to days.
Required Access
- State backend read/write.
- Lock table access.
- Cloud read permissions.
- Repository write access for recovery notes.
Common Failure Modes
- Lost Terraform state.
- Corrupted state.
- Stale lock records.
- Backend KMS permission failure.
- Human import error.