Fix Terraform State Lock Error — Unlock & Resume Safely
Direct answer
Terraform state lock errors occur when a previous operation did not release the lock, usually from a crash or interrupted CI/CD run. Confirm no other operation is running, then use terraform force-unlock with the lock ID to release the stale lock.
Structured breakdown
Cause
Terraform state lock errors occur when a previous operation didn't release the lock — usually due to a crash or timeout. Verify no other operation is running, then force-unlock with the lock ID.
Fix
- Check if another Terraform operation is actually running before unlocking
- Run terraform force-unlock <LOCK_ID> to release the stale lock
- Verify state file integrity after unlocking with terraform plan
Outcome
State lock is released, terraform plan runs successfully, and CI/CD pipeline concurrency is configured.
Common causes
- Previous terraform apply was interrupted or crashed
- CI/CD pipeline timed out during a Terraform operation
- Multiple users or pipelines running Terraform concurrently
- DynamoDB lock table has a stale lock entry (for S3 backend)
- Network interruption during state file write
Fix steps
- 1
Check if another Terraform operation is actually running before unlocking
- 2
Run terraform force-unlock <LOCK_ID> to release the stale lock
- 3
Verify state file integrity after unlocking with terraform plan
- 4
Implement CI/CD pipeline locking to prevent concurrent Terraform runs
- 5
Add timeout handling to your Terraform CI/CD pipeline configuration
Analyze this issue
Paste the issue description, logs, or symptoms into the fix tool to inspect this problem with your own runtime details.
Need more context?
If the standard steps do not resolve the issue, open the fix tool and include the current logs, configuration, and deployment changes.
Open Fix ToolFrequently asked questions
Related technical context
These examples show the commands, logs, and configuration patterns most often used to verify this issue.
Command examples
terraform force-unlock <LOCK_ID>terraform planaws dynamodb scan --table-name terraform-locks
Log snippet
Error: Error acquiring the state lock
ConditionalCheckFailedException: The conditional request failed
Lock Info:
ID: a1b2c3d4-e5f6-7890
Path: s3://my-bucket/terraform.tfstateConfig snippet
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
dynamodb_table = "terraform-locks"
}
}