terraform resource_error ai_generated true

错误:获取状态锁失败:条件检查异常:条件请求失败

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

ID: terraform/terraform-state-lock-unlock-failed

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

版本兼容性

版本状态引入弃用备注
Terraform v1.6 active
Terraform v1.7 active
Terraform v1.8 active
AWS Provider v5.0+ active

根因分析

另一个 Terraform 进程持有状态锁,或之前的锁未正确释放。

English

Another Terraform process holds the state lock, or a previous lock was not released properly.

generic

官方文档

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

解决方案

  1. Force unlock the state using 'terraform force-unlock <lock_id>' after verifying no other Terraform process is running. First, run 'terraform plan' to see if the lock is stale.
  2. If using S3 backend, manually delete the lock file from the DynamoDB table using AWS CLI: 'aws dynamodb delete-item --table-name <table-name> --key {"LockID":{"S":"<lock-id>"}}'

无效尝试

常见但无效的做法:

  1. 70% 失败

    Deleting the lock file can corrupt state if another process is still running, leading to state conflicts.

  2. 50% 失败

    Using a wrong lock ID will not release the lock, and may cause additional errors if the lock is actually held by a different process.

  3. 60% 失败

    The lock may still be held by the previous process, and restarting will not release it automatically.