If supported by the backend, terraform generally locks your tfstate files so that only one user can operate on your terraform state at once. Terraform generally automatically release the lock once the intended operation on the state file is over, which also helps terraform avoid corrupted state files. But sometimes due to network or any other issue your terraform state file lock remains even though the particular session that acquired the lock is ended. In this situation, you get the error acquiring the state lock: ConditionalCheckFailedException. You can use terraform force-unlock command to remove the lock.
Error message:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed Lock Info: ID: 9db890f1-b6je-c5i2-2278-8809f081debx Path: ... Operation: OperationTypePlan Who: ... Version: 0.12.25 Created: 2021-11-10 13:54:28.620874902 +0000 UTC Info: Terraform acquires a state lock to protect the state from being written by multiple users at the same time. Please resolve the issue above and try again. For most commands, you can disable locking with the "-lock=false" flag, but this is not recommended. |
Error resolution:
1 2 3 4 5 6 |
## Execute the below command to unlock terraform state file ## Replace the terraform force-unlock -force ## Or relaunch the plan with the following option terraform plan -lock=false |
I ran into the same issue when i was using terraform with S3 and dynamodb backend
**Reason** : i forcefully terminate apply process that actually prevents me to aquire the lock again
**Solution** : when it gets fail it return an ID with the ID we can unlock forcefully
terraform force-unlock -force 6638e010-8fb0-46cf-966d-21e806602f3a