ConditionalCheckFailedException cicd resource_error ai_generated true

错误:获取状态锁时出错:ConditionalCheckFailedException:条件请求失败

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

ID: cicd/terraform-state-lock-error

其他格式: JSON · Markdown 中文 · English
90%修复率
90%置信度
1证据数
2023-09-20首次发现

版本兼容性

版本状态引入弃用备注
Terraform 1.5.0 active
AWS Provider 5.10.0 active
DynamoDB active

根因分析

Terraform 无法获取 DynamoDB 中的状态锁,因为另一个进程持有锁,或者锁项已被并发操作修改。

English

Terraform failed to acquire the state lock in DynamoDB because another process holds the lock, or the lock item has been modified by a concurrent operation.

generic

官方文档

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

解决方案

  1. Identify the lock holder by checking DynamoDB table: aws dynamodb get-item --table-name <lock_table> --key '{"LockID": {"S": "<state_path>"}}'. If the lock is stale, use terraform force-unlock <lock_id> after manual verification.
  2. If the lock is held by a crashed process, wait for the lock timeout (default 15 minutes) and retry, or increase the lock timeout in the backend config.

无效尝试

常见但无效的做法:

  1. 30% 失败

    Force-unlocking without verifying who holds the lock can corrupt state or cause data loss.

  2. 10% 失败

    Deleting the DynamoDB lock table removes all locks but also breaks state locking for future operations.