Terraform State

· 1 min read · Terraform

Terraform state is a JSON file (terraform.tfstate) where Terraform and OpenTofu store the mapping between the resources in your code and the real objects in the cloud, plus their attributes. On every plan, the tool refreshes the state, compares it with the code and calculates the changes.

Why it matters #

  • Without the state, Terraform could not know that aws_instance.web is the instance i-0abc123.
  • It contains sensitive data in plain text (passwords, keys), so it must be protected: see secrets management and state encryption.
  • It must be shared and locked in a team, which is the job of a backend.
  • Never edit it by hand. Use terraform state commands or import, moved and removed blocks.

Backends tutorial, workspaces, drift and the cheat sheet.

More tutorials that use Terraform State

#Terraform #OpenTofu