Terraform's configuration files get all the attention in code review, but the state file is where most real incidents happen. State is the only record Terraform has of what it believes exists in the real world, and when that record diverges from reality — or two people write to it at once — the fallout ranges from a confusing plan to an accidental resource deletion. Treating state as an afterthought is the single most common mistake in teams adopting Terraform.
Remote backends and locking are not optional
Local state files (terraform.tfstate sitting in a repo or a laptop) fail the moment more than one person touches the infrastructure. Two applies running concurrently against local state will corrupt it or silently overwrite each other's changes. A remote backend with locking is table stakes for anything beyond a solo experiment:
terraform {
backend "s3" {
bucket = "example-org-tfstate"
key = "prod/network/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}The dynamodb_table entry provides state locking: Terraform writes a lock record before any plan or apply and refuses to proceed if another operation already holds it. Without this, a second terraform apply kicked off mid-run by CI or a teammate can interleave writes and leave state inconsistent with reality.
Splitting state by blast radius
A single monolithic state file covering an entire environment means every apply touches everything Terraform manages, and a mistake in one resource's plan can threaten unrelated resources through Terraform's dependency graph. Splitting state along natural boundaries — networking, data stores, application infrastructure — limits blast radius:
environments/
prod/
network/ # own state file
database/ # own state file
app-cluster/ # own state fileCross-state references use terraform_remote_state or, more commonly now, values passed through a shared data source like SSM Parameter Store, avoiding a hard coupling between state files that would force them to always apply in lockstep.
Handling drift without guessing
Drift happens constantly in real accounts — someone changes a security group rule in the console during an incident, or an auto-scaling event modifies a tag. terraform plan will show that drift on the next run, but blindly applying to "fix" it can undo a legitimate emergency change. Run refresh-only plans to see drift without proposing changes:
terraform plan -refresh-only -out=refresh.tfplan
terraform show refresh.tfplanThat separates "here's what changed outside Terraform" from "here's what I'm about to change," which matters a lot when the drift was intentional and needs to be reflected back into the .tf files rather than reverted.
Avoiding state file secrets exposure
State files store resource attributes in plain text, including ones you'd consider sensitive — database passwords set via a resource argument, generated TLS keys, connection strings. Anyone with read access to the state file has read access to those values regardless of how carefully the .tf files themselves handle secrets.
resource "aws_db_instance" "main" {
# ...
password = var.db_password # this ends up in state, in plain text
}Mitigate this by enabling backend encryption at rest (as in the S3 example above), restricting state bucket access as tightly as production database access itself, and preferring resources that reference secrets managers over ones that embed generated secrets directly. terraform state show should be treated as a command that can leak credentials, not a harmless inspection tool.
A worked example
Remote state S3 + Dynamo lock (or Terraform Cloud). State split per env/account. CI applies with OIDC. terraform plan in PRs. You never commit terraform.tfstate. Sensitive outputs marked. A drift job weekly.
Moving resources: moved blocks, not delete/create.
Failure modes
Local state on a laptop. One state for the whole company. Manual applies with different versions. Force-unlock as habit. Storing secrets as plain state attributes (they still end up in state — minimize). Parallel applies. Editing state JSON by hand.
terraform destroy in prod from muscle memory.
When this is the wrong tool
ClickOps for a one-off experiment you will throw away today. Terraform is the wrong tool to deploy app versions (GitOps). Not every SaaS needs a provider — a script may be less fiction. If the API has no idempotency, TF will hurt. Do not manage Kubernetes Deployments in TF while also using Argo on the same objects.
A worked failure mode
State is a git-committed file. Two people apply; one overwrites the other's resources, Terraform plans a destroy of production RDS because the state lost the mapping. Another team uses a remote backend without lock; same race. Secrets land in state as plaintext attributes. The failure is state as a casual file. Use remote state, locking, least-privilege access, encryption, and never -auto-approve a destroy you did not read.
Terraform state gymnastics are the wrong tool if you should not be managing that API with Terraform. Do not split state so finely you cannot boot an environment. One blob in git is the wrong backend. Use remote locked state when more than one human can apply.
A second, quieter failure is operational: the idea is copied from a talk into a path that has no rollback, no owner, and no metric that would show the invariant breaking. For "Terraform State Management Best Practices", that usually means a Friday deploy with production as the first realistic test. Write down the user-visible symptom, the invariant, and the revert before you scale the pattern. If revert is a data rewrite, you do not have a revert—you have a project. Practice the failure in staging with production-sized data at least once, or you will practice it on customers.