ConditionalCheckFailedException terraform resource_error ai_generated true

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

ID: terraform/state-lock-dynamodb-conditional-check-failed

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2023-05-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform 1.5 active
Terraform 1.6 active
Terraform 1.7 active
AWS Provider 5.0+ active

Root Cause

DynamoDB state lock table's condition expression failed, typically because another process holds the lock or the lock record is stale.

generic

中文

DynamoDB 状态锁表的条件表达式失败,通常是因为另一个进程持有锁或锁记录已过期。

Official Documentation

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

Workarounds

  1. 85% success Force unlock the state: terraform force-unlock LOCK_ID
    Force unlock the state: terraform force-unlock LOCK_ID
  2. 95% success Manually delete the lock item from DynamoDB table using AWS CLI: aws dynamodb delete-item --table-name terraform-locks --key '{"LockID": {"S": "<state-file-path>"}}'
    Manually delete the lock item from DynamoDB table using AWS CLI: aws dynamodb delete-item --table-name terraform-locks --key '{"LockID": {"S": "<state-file-path>"}}'

中文步骤

  1. Force unlock the state: terraform force-unlock LOCK_ID
  2. Manually delete the lock item from DynamoDB table using AWS CLI: aws dynamodb delete-item --table-name terraform-locks --key '{"LockID": {"S": "<state-file-path>"}}'

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Deleting the table loses all lock metadata and may cause state corruption if another process is actively using it.

  2. 90% fail

    Disabling locks risks concurrent writes and state corruption. Only safe for one-off operations.