Terraform — Production Errors, Mistakes and Recovery
The Terraform errors you meet in production (locks, drift, unknown values, cycles, forced replacement, providers, state and backends) and the mistakes behind most outages, with documented recovery steps and guardrails.
Overview
Terraform rarely fails because Terraform is broken. It fails because the state no longer matches reality (a killed run left a lock, someone clicked in the console, a state file was lost), because a plan was computed against the wrong inputs (wrong workspace, wrong account, a stale plan file), or because a reviewer did not read the one line that said must be replaced. The tool does exactly what the plan says, so the plan is where incidents are prevented.
Two published incidents show the pattern. On July 7, 2023, GitLab.com was down for web and API traffic from 16:25 to 18:42 UTC after an out-of-sync Terraform plan, prepared three weeks earlier, was executed against production (GitLab incident review). In March 2026, Alexey Grigorev described how, after moving to a new computer without his Terraform state, an AI coding agent ran terraform destroy and removed the DataTalks.Club course platform's production infrastructure, including the RDS database and its automated snapshots; AWS restored a snapshot exactly 24 hours after the database was deleted (his write-up).
Where incidents start
A plan is computed from three inputs: the configuration (the .tf files and variables), the state (its backend, lock and versions) and the real infrastructure behind the cloud APIs. A person or a CI job reviews the plan, and the apply then does exactly what it says. Most failures come from a mismatch between those three inputs, or from someone approving the wrong plan.
Key concepts
- State
- State lock
- Drift
- Forces replacement
- moved block
- removed block
- import block
- Dependency lock file
- Saved plan
- Policy as code
Interview questions
- What happens if you delete a resource block from a .tf file without running terraform destroy on it first?
- Someone ran terraform apply against the production workspace by mistake and it destroyed resources. What do you do in the first hour, and how do you prevent it from happening again?
- Terraform says the state is locked and the CI run that held the lock was killed. How do you safely recover?
- A routine change shows that a production database must be replaced. What do you do?
- terraform plan fails with Invalid for_each argument because keys cannot be determined until apply. How do you fix it properly?
- Someone opened a security group rule in the console during an incident. How do you reconcile it with Terraform?
- How do you rename resources or move them into a module without destroying anything?
- CI fails after a teammate upgraded a provider on a Mac, with a checksum error. What happened and how do you fix it?
- How would you design a production Terraform pipeline so a stale or unreviewed plan can never be applied?
- Your Terraform state contains database passwords. What is the risk and what do you change?
- How do you move an S3 backend from DynamoDB locking to S3 native locking, or to a new bucket, without losing state?
Sign up free to read the full topic
More DevOps topics
- Sources — Git, OCI, Helm, Bucket
- Static Analysis for C/C++ in CI
- Storage Errors — FailedMount, Pending PVCs, Multi-Attach and Full Volumes
- Strangler Fig
- Team Topologies
- Tekton
- 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
- Terraform Remote State — S3 + DynamoDB
- Test Pyramid
Start free on Cariara · Coding problems · System design studio