Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
How to fix 'Error acquiring the state lock' in Terraform. Safely unlock state files locked by crashed or interrupted operations.
Error acquiring the state lock: ConditionalCheckFailedExceptionTerraform 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.
# 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!
# 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"}}'# 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# 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=5mterraform plan — always review before applyingterraform validate — catches syntax errors earlyLearn to avoid these errors with interactive, project-based courses:
Related: How to install Terraform on macOS — our most popular installation guide.
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.
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
Fix terraform import errors when a resource already exists in state. Covers state rm, state show, reimport workflow, import blocks
Fix terraform too many command line arguments errors. Correct -var syntax, quote values with spaces, and learn proper Terraform CLI argument format for plan
Fix terraform invalid escape sequence errors. Double backslashes for Windows paths, use heredocs for regex, and learn all valid HCL escape sequences.