terraform state_error ai_generated true

Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed

ID: terraform/tf-state-lock-conflict

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Another Terraform process holds the state lock, or a previous run left a stale lock behind.

generic

Workarounds

  1. 90% success Use terraform force-unlock with the lock ID after verifying no other process is running
    terraform force-unlock LOCK_ID (the lock ID is shown in the error message)

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

  2. 85% success Wait for the other Terraform operation to complete
    Check the Lock Info in the error for who holds the lock; verify with CI/CD system if a pipeline is running

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

Dead Ends

Common approaches that don't work:

  1. Delete the DynamoDB lock table to clear the lock 90% fail

    Deleting the table removes all locking protection and may cause state corruption from concurrent operations

  2. Run terraform apply with -lock=false to bypass 75% fail

    Bypassing locks risks concurrent state modifications and state file corruption

Error Chain

Preceded by:
Frequently confused with: