cloud state_management ai_generated true

Error: Error acquiring the state lock: ConditionalCheckFailedException

ID: cloud/terraform-state-lock-dynamodb

Also available as: JSON · Markdown
90%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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.

generic

Workarounds

  1. 92% success Use terraform force-unlock with the lock ID
    terraform force-unlock LOCK_ID  # Lock ID is shown in the error message
  2. 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.
  3. 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:

  1. Wait for the lock to expire automatically 92% fail

    DynamoDB locks have no TTL by default. The lock will remain forever until manually removed.

  2. Run another terraform apply hoping it will override the lock 95% fail

    Concurrent applies with locked state cause state corruption. Never run parallel applies.

  3. 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.