# Error: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed: The conditional request failed because the lock has expired

- **ID:** `terraform/terraform-state-push-lock-expired`
- **Domain:** terraform
- **Category:** resource_error
- **Error Code:** `ConditionalCheckFailedException`
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

A state lock was acquired but expired (e.g., due to a long-running operation or stale lock), and Terraform's conditional update check failed because the lock item's version no longer matches.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.5.0 | active | — | — |
| 1.6.0 | active | — | — |
| 1.7.0 | active | — | — |
| 1.8.0 | active | — | — |

## Workarounds

1. **Force unlock the state using the lock ID: terraform force-unlock <LOCK_ID>. First, get the lock ID from the error message or by inspecting the DynamoDB table: aws dynamodb get-item --table-name terraform-lock --key '{"LockID": {"S": "<state-file-path>"}}' --projection-expression "LockID, Digest". Then run terraform force-unlock <LOCK_ID>.** (90% success)
   ```
   Force unlock the state using the lock ID: terraform force-unlock <LOCK_ID>. First, get the lock ID from the error message or by inspecting the DynamoDB table: aws dynamodb get-item --table-name terraform-lock --key '{"LockID": {"S": "<state-file-path>"}}' --projection-expression "LockID, Digest". Then run terraform force-unlock <LOCK_ID>.
   ```
2. **If the lock ID is not available, manually delete the lock item from DynamoDB after confirming no Terraform process is running: aws dynamodb delete-item --table-name terraform-lock --key '{"LockID": {"S": "<state-file-path>"}}'** (85% success)
   ```
   If the lock ID is not available, manually delete the lock item from DynamoDB after confirming no Terraform process is running: aws dynamodb delete-item --table-name terraform-lock --key '{"LockID": {"S": "<state-file-path>"}}'
   ```
3. **Increase the lock timeout in the backend configuration to prevent future expiration: backend "s3" { ... dynamodb_table = "terraform-lock" lock_timeout = "5m" }** (80% success)
   ```
   Increase the lock timeout in the backend configuration to prevent future expiration: backend "s3" { ... dynamodb_table = "terraform-lock" lock_timeout = "5m" }
   ```

## Dead Ends

- **Manually delete the DynamoDB lock item using AWS CLI without checking who holds the lock.** — This can cause state corruption if another Terraform process is still running; it should only be done after confirming no active operations. (70% fail)
- **Re-run terraform apply immediately without force-unlocking.** — The expired lock still exists in DynamoDB, so the new attempt will also fail with the same error. (90% fail)
- **Change the backend configuration to use a different DynamoDB table.** — This creates a new lock table but doesn't resolve the stale lock in the original table; state operations will still fail. (80% fail)
