Pcornel
Automation · Terraform / OpenTofu

State

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

Back to the Topic

Answer

Terraform/OpenTofu state maps configured resource instances to remote objects and stores metadata required for planning and lifecycle operations.

Remember

  • State snapshot ≠ live target; providers refresh/read remote systems to reconcile the cached management model with reality.
  • Terraform/OpenTofu command success ≠ target workload health; provider operations and application acceptance are separate proof boundaries.
  • The same repository ≠ same run when binary, provider/module versions, backend/workspace, variables, credentials or lock selections differ.
  • Treat Terraform and OpenTofu as separate implementations: verify behavior against the pinned tool and dependency versions rather than assuming interchangeability.

First checks

  • terraform state list — contents
  • terraform state pull > backup.tfstate — backup
  • terraform state mv <from> <to> — refactor (or moved blocks)

Commands

terraform state list
List resources tracked in the Terraform state.

Verify in this order

state → maps addresses to real IDs

Where it usually breaks

State snapshot ≠ live target; providers refresh/read remote systems to reconcile the cached management model with reality. The proof boundary ends where provider/state evidence stops and target-domain acceptance begins.

Configuration/input → graph/state refresh → plan → provider API request → provider terminal result → resource read-back → effective service state → workload.

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

Confirmation

Confirm action

Continue?