State Basics

View saved

What state stores

State tracks resource IDs and attributes Terraform manages. Without it, Terraform cannot reliably know what already exists.

Local state file

By default Terraform writes terraform.tfstate in the working directory. Do not edit it by hand.

ls
# terraform.tfstate
# terraform.tfstate.backup

Do not commit secrets blindly

  • Local demos may keep state on disk
  • Real teams use remote state (S3, Terraform Cloud, etc.) with locking
  • Add *.tfstate* to .gitignore for learning repos unless you know why you are committing

Refresh awareness

Terraform refreshes state from the real world during plan. If someone changed a resource outside Terraform, the plan may show drift.

terraform plan

Comments

One comment per signed-in account. Comments are saved with this page’s URL.