Solution:
Root Cause: Stale Lock Registration from Interrupted Execution When Terraform begins an operation against a remote backend (such as AWS S3 with DynamoDB, Terraform Cloud, or Azure Blob Storage), it writes a lock record containing a unique Lock ID, process ID, host, and timestamp. If the CLI process crashes, loses network connectivity, or is forcefully killed (
SIGKILL /
Ctrl+C), the lock record remains in the state database, blocking future executions.
Step-by-Step Fix: 1 Identify the Stale Lock ID:
Review the terminal output from terraform apply to locate the exact Lock ID string: Copy
text
Error: Error acquiring the state lock
Lock Info:
ID: e1a23b45-6789-0123-4567-89abcdef0123
Path: my-bucket/terraform.tfstate
Operation: OperationTypeApply
Who: user@dev-machine
Created: 2026-09-04 10:15:00 UTC
2 Verify Process Termination:
Confirm that the process owner listed under Who is not actively running Terraform on another machine or CI worker. 3 Execute Force-Unlock Command:
Run the unlock command using the extracted Lock ID: Copy
bash
terraform force-unlock e1a23b45-6789-0123-4567-89abcdef0123
Type yes when prompted to confirm unlocking. 4 Fallback Manual Unlock (AWS DynamoDB):
If force-unlock fails due to backend sync issues, navigate to the AWS DynamoDB Console. Locate the state lock table (e.g., terraform-state-locks). Search for item with LockID matching my-bucket/terraform.tfstate-md5 and delete the item record.