Fix Terraform "Error acquiring the state lock"
What to do when Terraform refuses to plan because the state is locked — and how to avoid it.
Problem
Error: Error acquiring the state lock
Lock Info:
ID: 2c3a...
Operation: OperationTypePlan
Who: ci@runner-9
Created: 2026-05-15 09:12:33Root cause
Another `terraform` invocation holds the lock — usually a CI job that crashed before releasing it. The lock entry sits in DynamoDB (S3 backend) or the equivalent for your backend.
Solution
Confirm no real job is still running
Check CI logs and any teammate's terminal. Force-unlocking a live job will corrupt your state.
Force unlock
terraform force-unlock 2c3a...Prevent it next time
- Wrap CI runs with a trap that releases the lock on failure.
- Set a sane `-lock-timeout=120s`.
- Don't share one state across many concurrent CI jobs — split workspaces.
Frequently asked questions
Related fixes
Terraform
4 minFix Terraform Provider Version Mismatch
Lock-file drift after a CI upgrade — how to align providers across environments.
#providers#lockfile
Terraform
5 minDetect and Fix Terraform Drift
When the real cloud no longer matches your state. Reconcile without nuking resources.
#drift#state#import
Weekly digest
One DevOps fix in your inbox each week
Short, practical, no fluff. Real errors, real fixes — straight from production postmortems.