RavGBGet a proposal

Writing

Reading a Terraform state file like a biography

A Terraform state file is not configuration, it is a record of what exists right now. Why losing it or letting it drift is dangerous, and how we read one without touching anything.

TL;DR

  • A Terraform state file is not your infrastructure code. It is a record of what Terraform believes actually exists in your AWS account right now, resource by resource.
  • Reading one is less like reading code and more like reading a biography: when each resource entered the picture, what it depends on, and what replaced what along the way.
  • Losing the state file, or letting it drift from what is actually running, is how a routine terraform apply starts trying to recreate or destroy things it should have left alone.
  • State should live in a remote backend with locking, the same way a company’s financial ledger should not live on one laptop, for exactly the same reason: one bad local copy should not be able to corrupt the shared truth.
  • Drift, where reality quietly stops matching the state file, is an early-warning signal worth treating seriously, not a cosmetic mismatch to ignore.
  • Our free AWS Cost and Reliability Audit reads configuration and current state to understand what exists. It never changes anything, by design.

What a state file actually is

Terraform’s own documentation describes state plainly: it is a JSON file that maps every resource block in your configuration to the real, specific thing it created in AWS, complete with that resource’s actual IDs and attributes. Your .tf files describe intent, what you want to exist. The state file is the only record of what Terraform believes it already made real. Without it, Terraform has no memory. It would look at your configuration, see no record of a database or a load balancer having been created, and try to create them again, even though they are already sitting there in your account.

Reading it like a biography

Open a real state file and it does not read like code. It reads like a record of a life: an entry for each resource, its address matching a block in your configuration, its real-world identifiers, and its relationships to the things it depends on, either because your configuration references them directly or because Terraform inferred the dependency from how resources connect. Resources that were replaced rather than updated show up as distinct entries in that history, not quiet overwrites, particularly when the state lives in a backend that keeps versioned history, such as an S3 bucket with versioning enabled or Terraform Cloud’s own state history.

Read enough of these across a few projects and a pattern becomes obvious: the shape of a state file tells you what order things were built in, what got replaced because a change required destroying and recreating rather than updating in place, and where a team’s infrastructure has accumulated resources nobody ever went back to clean up. It is a more honest record of what actually happened to an AWS account than the commit history of the Terraform code usually is, because the state reflects reality, not intention.

Why losing it is dangerous

A missing or badly out-of-sync state file does not fail loudly and safely. It fails by making Terraform act on a false belief about what exists. If the state says nothing exists where something actually does, a plan can propose creating duplicates of live infrastructure. If state has drifted from reality, for example because someone made a change directly in the AWS console instead of through Terraform, a plan can show “destroy and recreate” for a resource that is actually fine, simply because Terraform’s record of it no longer matches the truth. Terraform’s own documentation on state locking describes a related failure mode directly: two people or processes running terraform apply against the same state at the same time without locking can corrupt it outright, each one writing over the other’s changes.

None of this is a defect in Terraform. It is the predictable consequence of treating a single source of truth carelessly, the same way a shared spreadsheet with no version control eventually ends up with someone’s edits silently lost.

Where it should live

State belongs in a remote backend built for this, such as an S3 bucket paired with a DynamoDB table for locking, or a managed option like Terraform Cloud, never on a single laptop and never committed into a git repository. A laptop copy can be lost, overwritten, or simply out of date the moment two people touch infrastructure in the same week. A copy in git is worse: state files often contain sensitive values in plain text, and git history does not forget. The comparison that tends to land with a non-technical founder is a company’s accounting ledger: nobody would accept it living as an Excel file on one person’s machine with no backup and no lock against two people editing it at once, and infrastructure state deserves the same seriousness, not less, because it is the one record of what is actually running and costing money.

This connects directly to the kind of configuration review we cover in first things we check in your AWS account and the deeper reliability work in our EKS upgrade checklist: a team that has never looked closely at how its infrastructure is tracked is usually also the team that has never looked closely at whether its backups restore or its NAT Gateway bill makes sense.

Drift: when the biography stops matching the person

Drift is what happens when the real infrastructure and the state file’s record of it quietly diverge, almost always because a manual change was made somewhere Terraform does not know to look: a security group rule added directly in the console during an incident, an instance type bumped up temporarily and never reverted in code, a database parameter tweaked by hand. Running terraform plan after drift has occurred surfaces it as proposed changes that look alarming but are actually Terraform trying to reconcile a reality it was not told about. Treating a drift warning as noise to dismiss is how small, well-intentioned manual fixes accumulate into infrastructure nobody can confidently describe anymore.

What our free audit actually reads

The free AWS Cost and Reliability Audit looks at your account’s configuration, including infrastructure-as-code and current state where it exists, to understand what is actually running, what it costs, and where the reliability and security gaps are, entirely by reading, never by changing. The audit does not touch anything inside the account, does not read data or code, and has no access to the Kubernetes API inside any EKS cluster, so clusters are reviewed from the AWS side rather than from within. Exactly what the role can and cannot see is documented in full on how our read-only audit role works, and we confirm the exact accounts in scope with you in writing before anything is deployed.

Talk to us about your infrastructure’s record

If you are not sure your team’s Terraform state matches what is actually running, or state has never lived anywhere more durable than someone’s laptop, tell us about your setup and we will give you a straight answer about what the free audit would and would not catch. We reply within one or two business days.

The monthly AWS note

One AWS cost or reliability fix a month.

For small SaaS teams running AWS without a DevOps hire. One short email a month:

  • One concrete fix for cost or reliability, with the console steps or CLI command
  • A common AWS mistake small teams make, and how to avoid it
  • New RavGB guides and free tools, before anyone else

From RavGB Technologies Inc., Saddlemont NE, Calgary, AB, Canada (hello@ravgb.com). By subscribing you agree to receive this monthly email. No spam, we never share your address, and you can unsubscribe in one click, any time.