Skip to content
TerraformIaCStateDevOps

What Is Terraform State and Why Does It Matter So Much?

June 22, 2026 · 10 min read

Last verified: 2026-07-17

Frequently Asked Questions

What is Terraform state?

State is the ledger where Terraform remembers what it created in the real world. When you run 'terraform apply', Terraform writes the ID and attributes of every resource it creates into a JSON file (terraform.tfstate); it is the bridge between your code and the real infrastructure.

Why does the Terraform state file matter?

On the next plan/apply, Terraform compares the 'desired state' in your code with the 'current state' in the file and computes the diff. Without state, Terraform couldn't tell whether a resource is one it manages or one someone else created.

Why is local Terraform state dangerous?

When everyone on the team has a different copy of state, it leads to conflicts and deleted resources. If the state file is lost, Terraform no longer recognizes your infrastructure; secrets can also sit in plaintext inside state, which is unsafe on a laptop.

Why use remote state and locking in Terraform?

In production you should keep state in a remote backend such as S3, GCS, or Terraform Cloud. A lock prevents two people from running apply at once and corrupting state; for example, with an S3 backend a DynamoDB table is used for locking.

How do you manage Terraform state without breaking it?

Never hand-edit terraform.tfstate; use 'terraform state mv' when renaming a resource and 'terraform import' to adopt a hand-created resource. Also, don't force-unlock blindly, since unlocking a genuinely running apply corrupts state, so verify the owner via Lock Info first.

Reading isn't enough — do it.

Practice these topics in an interactive terminal in your browser.