Introduction Terraform uses state locking to prevent concurrent modifications. When a lock is held by a stale process (crashed CI run, interrupted apply), all subsequent Terraform operations are blocked with a "state lock contention" error.
Symptoms - `terraform plan` or `terraform apply` returns: "Error acquiring the state lock" - Error: "ConditionalCheckFailedException: The conditional request failed" - LockInfo shows: "ID", "Path", "Operation", "Who", "Version", "Created" - All Terraform operations blocked waiting for lock - Lock held for hours or days by a process that no longer exists
Common Causes - CI/CD pipeline crashed or killed during Terraform run - User interrupted terraform apply with Ctrl+C - Network disconnection during state write - Multiple people running Terraform simultaneously - DynamoDB table not properly configured for locking
Step-by-Step Fix 1. **Check who holds the lock**: The error message shows LockInfo: ``` Lock Info: ID: abc-123-def Path: my-bucket/env:/prod/terraform.tfstate Operation: OperationTypeApply Who: user@hostname Version: 1.6.0 Created: 2026-04-08 15:30:00.000 +0000 UTC ```
- 1.Verify the process is actually dead:
- 2.Check if the user/process from LockInfo is still running Terraform. If not, it's a stale lock.
- 3.Force unlock with the Lock ID:
- 4.```bash
- 5.terraform force-unlock abc-123-def
- 6.
` - 7.Only do this after confirming no other Terraform process is actually running.
- 8.Check DynamoDB lock table:
- 9.```bash
- 10.aws dynamodb get-item --table-name terraform-lock \
- 11.--key '{"LockID": {"S": "my-bucket/env:/prod/terraform.tfstate-md5"}}'
- 12.
` - 13.Verify state integrity after unlocking:
- 14.```bash
- 15.terraform plan
- 16.# Should run without lock errors and show the expected diff
- 17.
`