Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

  1. Confirm that no other Terraform job is currently running in the CI/CD pipeline or locally.
  2. 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"}}'
  1. Verify the lock has been removed:
aws dynamodb scan --table-name tf-state-locks
  1. Re-run the Terraform pipeline.

Use this procedure only for stale locks. Do not remove the lock if another deployment is still running.