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
- Tekton
- Terraform — Production Errors, Mistakes and Recovery
- Terraform & OpenTofu
- Terraform count vs for_each
- Terraform Essentials — Plan and Apply, Variables, Outputs, Data Sources, and Sharing State at Scale
- Terraform in CI/CD Pipelines
- Test Pyramid
- The C/C++ Compilation Model
- The flux CLI
- The Three Ways
- Toil Reduction & Automation Strategy
- Trunk-Based Development
Start free on Cariara · Coding problems · System design studio