Table of Contents
The Error
Error acquiring the state lock: ConditionalCheckFailedException
What Causes This
Terraform locks state files to prevent concurrent modifications. If a terraform apply crashes, gets killed, or times out, the lock may remain. This prevents any further operations until the lock is released.
How to Fix It
Solution 1: Force Unlock (Use With Caution!)
# Get the Lock ID from the error message
# Error message shows: Lock Info: ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
terraform force-unlock LOCK_ID_HERE
⚠️ Only use force-unlock when you’re certain no other operation is running!
Solution 2: Check DynamoDB Lock Table
# If using S3 backend with DynamoDB locking
aws dynamodb scan \
--table-name terraform-state-lock \
--filter-expression "attribute_exists(LockID)"
# Delete stale lock manually
aws dynamodb delete-item \
--table-name terraform-state-lock \
--key '{"LockID": {"S": "your-bucket/path/terraform.tfstate"}}'
Solution 3: Verify No Running Operations
# Check if another terraform process is running
ps aux | grep terraform
# Check CI/CD pipelines for running jobs
# GitLab, GitHub Actions, Jenkins — make sure no parallel runs
Solution 4: Prevent Future Lock Issues
# Set a reasonable lock timeout
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-state-lock"
}
}
# Use -lock-timeout to wait instead of failing immediately
terraform apply -lock-timeout=5m
Prevention Tips
- Pin provider versions — avoid surprise breaking changes
- Use CI/CD — catch errors before they hit production
- Test with
terraform plan— always review before applying - Keep Terraform updated — newer versions have better error messages
- Use
terraform validate— catches syntax errors early
Hands-On Courses
Learn to avoid these errors with interactive, project-based courses:
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
- Terraform Cheat Sheet — quick reference for all commands
Related Articles
- Terraform Troubleshooting - Common Errors and Solutions
- Terraform Enabling and Using Debugging
- Debugging with TFLint
Conclusion
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

