Skip to content

Terraform State Lock

Error message

                Error: Error acquiring the state lock
              

Quick summary

Another Terraform process or a stale lock is holding the state lock, preventing the current operation from proceeding.

Why this happens

  • Another team member or CI job is running Terraform simultaneously

  • A previous Terraform run was interrupted and left a stale lock

  • The lock table/bucket is in a different region or account

  • Permissions to the lock table/bucket are insufficient

Minimal example

✗ Broken code
$ terraform apply
Error: Error acquiring the state lock
Lock Info:
  ID: 12345-abcde
✓ Fixed code
# Verify no one else is running terraform
# Then force unlock if stale
terraform force-unlock 12345-abcde
terraform apply  # now works

A stale lock is preventing the apply. The fix force-unlocks it (only if you are sure no one else is running Terraform).

How to diagnose

  • Check if another Terraform process is running

  • View the lock info: terraform force-unlock -info <lock-id> (if supported)

  • Check the DynamoDB table (for AWS S3 backend) or Consul for lock entries

  • Verify the backend configuration in the Terraform code

How to fix

  • Wait for the other Terraform operation to complete

  • Force unlock if the lock is stale: terraform force-unlock <lock-id>

  • Fix the backend configuration to point to the correct lock table/bucket

  • Ensure the IAM user has permissions to the lock table

How to prevent

  • Use a remote backend with locking (S3 + DynamoDB, or Terraform Cloud)

  • Coordinate Terraform runs in CI to avoid concurrent operations

  • Use a CI queue to serialize Terraform runs

Related Resources

Related Glossary

← Back to language