Pcornel
Automation · Automation Troubleshooting

Terraform State Problems

Cheat sheet · https://pcornel.dk/topic.php?topic=6061

Back to the Topic

Answer

Terraform State Problems isolates failures involving backend access, workspace selection, state locks, serial/lineage, stale or missing objects, address moves, imports and divergence between Terraform/OpenTofu state and live infrastructure.

Remember

  • State file exists ≠ correct backend/workspace is selected.
  • Lock present ≠ lock is stale.
  • Resource absent from state ≠ safe to create it.
  • Import succeeds ≠ configuration and lifecycle semantics are complete.

First checks

  • terraform state list — contents
  • terraform force-unlock <id> — stale lock (verify first)
  • terraform state pull > backup.tfstate — backup before fixes

Verify in this order

state issue → backup → state command → clean plan

Where it usually breaks

Terraform/OpenTofu state repair proves consistency only for the selected backend/workspace and modeled resources; it does not prove every external dependency or workload is healthy.

Terraform State Problems troubleshooting proof-boundary map

BoundaryHealthy evidenceSuspicious evidence
Symptom / scopeTime window, immutable source/run identity, effective inputs and exact targets are explicitFloating source, changed inputs or ambiguous targets destroy reproducibility
First failed boundaryTransport/auth/dependency/render/operation evidence identifies the earliest divergenceInvestigation starts at the final error and skips earlier unproven boundaries
Effective outcomeController result is paired with target read-back and workload/service acceptanceGreen execution state or changed symptom substitutes for effective-state verification
Recovery / closureMinimal change restores the original test and regression/partial-state checks are cleanBroad retry or unrelated edits make the incident non-reproducible and hide residual state

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6061

Confirmation

Confirm action

Continue?