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

- **ID:** `cicd/terraform-state-lock-error`
- **领域:** cicd
- **类别:** resource_error
- **错误码:** `ConditionalCheckFailedException`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform 1.5.0 | active | — | — |
| AWS Provider 5.10.0 | active | — | — |
| DynamoDB | active | — | — |

## 解决方案

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

## 无效尝试

- **** — Force-unlocking without verifying who holds the lock can corrupt state or cause data loss. (30% 失败率)
- **** — Deleting the DynamoDB lock table removes all locks but also breaks state locking for future operations. (10% 失败率)
