← All posts

Terraform state: what it is and why you lock it

3 April 2025 · 1 min read
#terraform#iac

Terraform state confuses people at first. It's simpler than it sounds.

State is Terraform's memory. It's a file mapping each resource in your code to the real thing in the cloud. Without it, Terraform can't tell "this already exists" from "create a new one".

Rules I follow:

  • Keep it remote. A state file on one laptop is a single point of failure and can't be shared.
  • Lock it. Two people applying at once can corrupt state. A lock means the second run waits.
  • Version it. If something goes wrong, you can roll the state file back.
  • Never edit it by hand. Use terraform state commands, or import and moved blocks in code.
  • Treat it as sensitive. State can contain secrets, so lock down who can read it.

Get state right on day one and most Terraform horror stories never happen.

T
Written by Teza Wynn Htut

Cloud and infrastructure engineer in Auckland. I write down the fixes and lessons from things I build, and make tutorial videos on YouTube.

Watch on YouTube