When the Terraform remote state lock fails
If the Terraform CI/CD pipeline (for staging or production) is blocked by a stale remote lock in the DynamoDB state lock table (typically named tf-state-locks), follow these steps:
Warning: Only delete the lock if you have confirmed that no active Terraform operation is running. Removing a lock while a deployment is in progress can corrupt the Terraform state file and cause infrastructure inconsistencies.
- Confirm that no other Terraform job is currently running in the CI/CD pipeline or locally.
- Delete all stale lock items from the DynamoDB lock table:
# List current lock items
aws dynamodb scan --table-name tf-state-locks
# Delete a specific lock item (replace LOCK_ID with the actual LockID value)
aws dynamodb delete-item \
--table-name tf-state-locks \
--key '{"LockID": {"S": "LOCK_ID"}}'
- Verify the lock has been removed:
aws dynamodb scan --table-name tf-state-locks
- Re-run the Terraform pipeline.
Use this procedure only for stale locks. Do not remove the lock if another deployment is still running.