# 错误：获取状态锁失败：LockInfoError：条件请求失败。锁已过期或由另一个进程持有。锁ID：abc123

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

## 根因

远程后端（如 AWS DynamoDB）中的 Terraform 状态锁已过期或因先前崩溃的操作而卡住，阻止新操作获取锁。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform 1.5 | active | — | — |
| Terraform 1.6 | active | — | — |
| Terraform 1.7 | active | — | — |
| AWS Provider 5.0 | active | — | — |

## 解决方案

1. ```
   Force unlock the state using terraform force-unlock <LOCK_ID> after verifying no other process is running. First, check the lock info with terraform plan or by querying the DynamoDB table.
   ```
2. ```
   Manually delete the lock item from the DynamoDB table using AWS CLI if force-unlock fails due to permissions or network issues.
   ```
3. ```
   Increase the lock timeout in the backend configuration by setting the 'lock_timeout' parameter (e.g., 60s) to allow longer operations to complete before the lock expires.
   ```

## 无效尝试

- **** — terraform init only initializes the backend configuration; it does not manage locks. (90% 失败率)
- **** — This is an extreme measure that should only be used if the state is backed up; it is not a safe fix for lock issues. (95% 失败率)
- **** — The lock is checked at the beginning of any state-modifying operation, regardless of approval flags. (85% 失败率)
