STATE_LOCK_EXPIRED
cicd
resource_error
ai_generated
true
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
88%Fix Rate
86%Confidence
1Evidence
2023-11-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Terraform 1.5 | active | — | — | — |
| Terraform 1.6 | active | — | — | — |
| Terraform 1.7 | active | — | — | — |
| AWS Provider 5.0 | active | — | — | — |
Root Cause
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中文
远程后端(如 AWS DynamoDB)中的 Terraform 状态锁已过期或因先前崩溃的操作而卡住,阻止新操作获取锁。
Official Documentation
https://developer.hashicorp.com/terraform/language/state/lockingWorkarounds
-
90% success 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.
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.
-
85% success Manually delete the lock item from the DynamoDB table using AWS CLI if force-unlock fails due to permissions or network issues.
Manually delete the lock item from the DynamoDB table using AWS CLI if force-unlock fails due to permissions or network issues.
-
80% success 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.
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.
中文步骤
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.
Manually delete the lock item from the DynamoDB table using AWS CLI if force-unlock fails due to permissions or network issues.
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.
Dead Ends
Common approaches that don't work:
-
90% fail
terraform init only initializes the backend configuration; it does not manage locks.
-
95% fail
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.
-
85% fail
The lock is checked at the beginning of any state-modifying operation, regardless of approval flags.