What is Terraform state?

Answer

Terraform state is a JSON file (terraform.tfstate) that records the mapping between your Terraform configuration and the actual deployed infrastructure. Terraform uses state to: determine what changes are needed (compare desired config vs actual state), track resource metadata (IDs, ARNs), and manage dependencies. By default, state is stored locally in terraform.tfstate. For team environments, store state remotely (S3, Azure Blob, GCS, Terraform Cloud) with state locking (DynamoDB, Blob lease) to prevent concurrent modifications. Never edit state manually — use terraform state commands. Protect state files — they contain sensitive values like passwords and private keys. Enable versioning on the remote backend bucket for rollback capability.