cloud
state_management
ai_generated
true
Error: Error acquiring the state lock: ConditionalCheckFailedException
ID: cloud/terraform-state-lock-dynamodb
90%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
Terraform S3 backend uses DynamoDB for state locking. If a previous terraform apply was killed (Ctrl+C, CI timeout, OOM), the lock remains forever. force-unlock is scary but sometimes necessary.
genericWorkarounds
-
92% success Use terraform force-unlock with the lock ID
terraform force-unlock LOCK_ID # Lock ID is shown in the error message
-
95% success Check if another process is actually running before force-unlock
Check CI/CD pipelines, other terminals. Only force-unlock if you're SURE no other apply is running.
-
85% success Add -lock-timeout=5m to terraform commands in CI to handle transient locks
terraform apply -lock-timeout=300s # wait up to 5 minutes for lock release
Dead Ends
Common approaches that don't work:
-
Wait for the lock to expire automatically
92% fail
DynamoDB locks have no TTL by default. The lock will remain forever until manually removed.
-
Run another terraform apply hoping it will override the lock
95% fail
Concurrent applies with locked state cause state corruption. Never run parallel applies.
-
Delete the DynamoDB lock item directly from console
78% fail
Deleting the item works but bypasses Terraform's lock check. If another process IS running, state corruption follows.