liveBook · Manning

Terraform state file

As explained in Grokking Software Architecture

A Terraform state file records the resources Terraform manages and maps its configuration to real infrastructure.

Think of Terraform’s state file as its digital memory bank: it records what Terraform has built so it can compare your configuration with the real infrastructure and make only needed changes. section 9.7 section 9.7.2

Remembering what already exists

Run a configuration for one Postgres database on Monday, then run it again on Tuesday: Terraform compares your code, its state, and the cloud, and does nothing if they agree. Change allocated_storage from 50 to 100, and it updates the drive to match. section 9.7.2

That memory needs protection:

  • If a local state file is lost, Terraform may forget an existing resource and create a duplicate, leaving the original unmanaged. section 9.7.3
  • Teams can avoid lost updates and simultaneous-deployment collisions by storing state remotely and using locking. section 9.7.3
Figure 9.5 Terraform doesn't just "run scripts"; it reconciles reality with your text files!

See Terraform reconciling declared configuration with remembered state and real infrastructure. section 9.7.2

How Grokking Software Architecture covers it

How deep it goes
Works through a three-way comparison and concrete updates, then explains loss and team risks without detailing the file format.
Examples
Uses a repeatedly applied Postgres configuration and a storage increase from 50 to 100.
What you can do after
Understand why Terraform can recognize existing infrastructure and apply only the changes needed to match configuration.
How it connects
Connects state to Terraform, declarative configuration, Infrastructure as Code, remote state, and state locking.

Also explained in

Compare how 3 books explain Terraform state file →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.