Terraform Remote State — S3 + DynamoDB

Terraform state file (terraform.tfstate) records real infrastructure. Remote state in AWS S3 prevents local machine dependency and enables team collaboration. DynamoDB state locking prevents two people applying simultaneously. Single source of truth, versioning via S3, lock table with LockID/Status/Info.

Overview

What Terraform state is

Terraform state is a JSON file (terraform.tfstate) that records the real infrastructure Terraform manages. It maps .tf resource definitions to actual cloud resource IDs, attributes and dependencies. Without accurate state, Terraform cannot plan or destroy correctly.

The state file sits between your .tf resource definitions and the real cloud resources. Moved to a remote backend, S3 plus a lock, it becomes one source of truth that the whole team and CI share.

Key concepts

  • terraform.tfstate
  • S3 backend configuration
  • DynamoDB lock table
  • terraform_remote_state
  • State encryption
  • State locking danger: stale lock

Interview questions

  • What is Terraform state and why does remote state matter?
  • What happens if a Terraform apply crashes mid-run and the DynamoDB lock is not released?

Sign up free to read the full topic

More DevOps topics

Start free on Cariara · Coding problems · System design studio