Skill 2.4.2

State contents and metadata

Key Concepts

By default, state is written to terraform.tfstate in the working directory, with the previous version kept in terraform.tfstate.backup. It contains a lineage, a unique ID assigned when the state is first created, and a serial number that increases with each write. Terraform uses them to refuse accidentally pushing an older or unrelated state over a newer one.

Each resource entry records its mode (managed or data), type, name, provider configuration and, for each instance, all attributes the provider returned. Before planning, Terraform refreshes state by reading each object from the platform, so the plan is based on current reality. The format is internal and may change, so never edit it by hand; use Terraform commands and configuration blocks instead.