terraform state_error ai_generated partial

Error acquiring the state lock: ConditionalCheckFailedException

ID: terraform/state-lock-dynamodb

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Another Terraform process holds the state lock (DynamoDB). Wait or force-unlock.

generic

Workarounds

  1. 90% success Wait for the other process to finish — check the Lock Info in the error for who holds it
    # The error shows Lock Info with:
    # ID, Who, Operation, Created
    # Check if that user/CI job is still running
    # Wait for it to complete, or contact the person
    
    # If the process crashed, use force-unlock:
    terraform force-unlock <LOCK_ID>

    Sources: https://developer.hashicorp.com/terraform/language/state/locking

  2. 88% success If the lock is stale (crashed process), force-unlock: terraform force-unlock <LOCK_ID>
    terraform force-unlock

    Sources: https://developer.hashicorp.com/terraform/cli/commands/force-unlock

  3. 82% success Check CI/CD for parallel Terraform runs that need serialization
    Check CI/CD for parallel Terraform runs that need serialization

    Sources: https://developer.hashicorp.com/terraform/language/state/locking

Dead Ends

Common approaches that don't work:

  1. Delete the DynamoDB lock item directly 80% fail

    May cause state corruption if another process is running

  2. Disable state locking with -lock=false 85% fail

    Risks concurrent state modifications — data corruption

Error Chain

Frequently confused with: