TOPIC IAC
Terraform State the source of truth Terraform uses to reconcile real-world resources
IN 10 SECONDS
Every `terraform apply` records what it created in a state file (usually `terraform.tfstate`). On subsequent runs, Terraform compares the state against both your config and the real cloud provider — creating, updating, or deleting resources to match. The state is the bridge between your `.tf` files and what's actually deployed.
GOTCHA State contains all your resource IDs and sometimes secrets (plaintext passwords in early resources). Always encrypt state at rest and in transit. Use `terraform state rm` carefully — it forgets a resource without destroying it.
HOW STATE DRIVES A PLAN
01 Terraform reads the backend (local file, S3, or Consul) to fetch the current state.
02 Terraform refreshes state by querying the provider for the real-world attributes of each resource.
03 Terraform compares refreshed state against your `.tf` config to compute a diff.
04 Terraform prints the plan: resources to create (green), destroy (red), or modify in-place (yellow).
05 Apply executes the plan, updating state after each API call. If it crashes mid-way, you get a partial state.
POKE IT YOURSELF
terraform state list — show every resource tracked in state
terraform state show RESOURCE_ADDR — inspect a single resource's attributes
Drill this topic →
~85 sec read