STATE_LOCK_EXPIRED cicd resource_error ai_generated true

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

Error: Error acquiring the state lock: LockInfoError: The conditional request failed. The lock has expired or is held by another process. Lock ID: abc123

ID: cicd/terraform-state-lock-expired

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

版本兼容性

版本状态引入弃用备注
Terraform 1.5 active
Terraform 1.6 active
Terraform 1.7 active
AWS Provider 5.0 active

根因分析

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

English

Terraform state lock in a remote backend (e.g., AWS DynamoDB) has expired or is stuck due to a previous crashed operation, preventing new operations from acquiring the lock.

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 90% 失败

    terraform init only initializes the backend configuration; it does not manage locks.

  2. 95% 失败

    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.

  3. 85% 失败

    The lock is checked at the beginning of any state-modifying operation, regardless of approval flags.