Terraform State Lock Error — State File Locked by Another Process
Errorcommand
Overview
Fix Terraform state lock errors when another process holds the lock on the state file, preventing plan, apply, or destroy operations.
Key Details
- Terraform locks the state file during write operations to prevent concurrent modifications
- State locking prevents two terraform apply commands from running simultaneously on the same state
- Remote backends (S3+DynamoDB, Terraform Cloud, GCS) provide distributed locking
- Lock information includes: who locked it, when, and which operation
- A stuck lock usually means a previous Terraform process crashed without releasing the lock
Common Causes
- Previous terraform apply or plan was interrupted (Ctrl+C, crash, network disconnect)
- Another team member is running Terraform against the same state file simultaneously
- CI/CD pipeline hung or timed out while holding the state lock
- DynamoDB lock table (for S3 backend) has a stale lock entry
Steps
- 1Check if another Terraform process is actually running — do not force unlock if it is
- 2Force unlock the state: 'terraform force-unlock LOCK_ID' (use the lock ID from the error message)
- 3For S3+DynamoDB backend: check the DynamoDB lock table for stale entries and delete manually if needed
- 4For Terraform Cloud: check the workspace runs page for stuck runs and cancel them
- 5Prevent future issues: use CI/CD pipelines with proper timeouts and ensure only one pipeline runs at a time
Tags
terraformstate-lockinfrastructureiacdevops
Related Items
More in Command
linux-exit-code-127Linux Exit Code 127 — Command Not Found
Warninglinux-exit-code-126Linux Exit Code 126 — Permission Denied
Warninglinux-segmentation-faultLinux Segmentation Fault (Signal 11)
Errorlinux-killed-signal-9Linux Process Killed (Signal 9)
Errorlinux-ansible-playbook-errorsAnsible Playbook Errors — Task Failures, SSH Connectivity, and Variable Resolution Issues
Warninglinux-terraform-errorsTerraform Errors — Plan, Apply, and State Management Failures
WarningFrequently Asked Questions
Only if you are certain no other Terraform process is running against this state. Force-unlocking while another apply is in progress can corrupt the state file. Always verify first.