Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Terraform state: shared ownership and safe plans

Last updated: 5 Oct 20266 min read
tutorial
IntermediateBy AITrove Editorial

Terraform state records which remote objects correspond to resources in configuration. A plan compares configuration and observed state before an apply. Teams need a protected remote state store with access control, versioning, and a backend that supports locking; a local state file committed to Git is neither a safe coordination method nor a suitable secret store.

Operational decision

For a fraud-review service, keep network infrastructure and application-level resources in separately owned state units. Run validation and a plan on the proposed configuration, then apply the approved revision with the same provider lockfile and a serialized state writer. Treat saved plan files and state as sensitive because provider attributes can contain secret material. A plan is also time-sensitive: another actor may change infrastructure after it was reviewed. Recheck drift before apply and abort if the target state no longer matches expectations. The commands below demonstrate review and apply order but do not configure a backend; choose a backend with locking and protected access before collaborative use. Never disable locking to make a stuck pipeline pass.

bash
terraform init -input=false
terraform fmt -check
terraform validate
terraform plan -out=reviewed.plan
terraform apply reviewed.plan

Cost and verification

Remote state adds storage and access-management cost. Locking serializes writes and may make a queued apply wait, which is preferable to corrupting shared state. A saved plan can become stale if remote resources change; keep the approval window short and let the apply fail safely when assumptions no longer hold. Do not print state or plan output into broadly visible logs. Commit configuration and the provider lockfile, while excluding state, state backups, and saved plans from version control.

Common Mistakes

  • Do not commit state or saved plans.
  • Do not disable locking to clear contention.
  • Do not apply an old plan after unrelated infrastructure changes.

Connected lessons

Operational follow-up

Advanced follow-up

Advanced follow-up

Advanced follow-up

Advanced follow-up

Continue with: Infrastructure plans: classify every action before apply.

devops
operations
Storage details