# Error: Error acquiring the state lock. Lock Info: Lock ID: <id>. Error: ConditionalCheckFailedException: The conditional request failed

- **ID:** `policy/terraform-state-lock-timeout-dynamodb`
- **Domain:** policy
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Terraform state locking via DynamoDB fails when another process holds the lock longer than the default retry timeout, often due to long-running applies or stale locks.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Terraform v1.5.0 | active | — | — |
| Terraform v1.6.0 | active | — | — |
| DynamoDB standard table | active | — | — |

## Workarounds

1. **Identify the lock holder via AWS CLI: aws dynamodb get-item --table-name terraform-locks --key '{"LockID": {"S": "<lock-id>"}}'. If the holder is stale, run terraform force-unlock -force <lock-id>.** (85% success)
   ```
   Identify the lock holder via AWS CLI: aws dynamodb get-item --table-name terraform-locks --key '{"LockID": {"S": "<lock-id>"}}'. If the holder is stale, run terraform force-unlock -force <lock-id>.
   ```
2. **Increase the lock retry timeout in terraform block: terraform { backend "s3" { lock_timeout = "5m" } } to allow longer waits.** (75% success)
   ```
   Increase the lock retry timeout in terraform block: terraform { backend "s3" { lock_timeout = "5m" } } to allow longer waits.
   ```
3. **Implement a pre-apply check script that verifies no other CI pipeline is running using the same state file.** (70% success)
   ```
   Implement a pre-apply check script that verifies no other CI pipeline is running using the same state file.
   ```

## Dead Ends

- **** — Running terraform force-unlock without verifying the lock holder can corrupt the state if the original process is still running. (60% fail)
- **** — Deleting the DynamoDB lock table entirely loses all lock state and requires reinitialization. (80% fail)
- **** — Manually editing the DynamoDB item with incorrect permissions may cause AccessDenied errors. (50% fail)
