Error fixTerraform · 3 min read · Updated 4 Dec 2026

Terraform "Error acquiring the state lock": How to Fix

Fix Terraform "Error acquiring the state lock": find who holds the lock, wait for the other run, and use force-unlock safely with S3, Azure or HCP Terraform.

QUICK ANSWERTerraform locks the state file during plan and apply so two runs cannot change the same infrastructure at once. "Error acquiring the state lock" means another run holds the lock, or a crashed run left it behind. The error shows the lock ID, who created it and when. If that run is still active, wait. If it is truly dead, run terraform force-unlock <LOCK_ID>, but only after confirming nobody is applying.
Terraform state lock error: causes and fixes
Terraform state lock error: causes and fixes

Read the lock information

Error: Error acquiring the state lock
Lock Info:
  ID:        6f1c2e9a-...
  Path:      my-tf-state/prod/network.tfstate
  Operation: OperationTypeApply
  Who:       jenkins@build-agent-3
  Created:   2026-12-04 09:12:44 UTC

The Who and Created fields tell you whether a teammate or a CI job is running right now, or whether the lock is hours old from a cancelled job.

Fix it step by step

  1. Check whether a pipeline or teammate is running Terraform on the same state. If yes, wait for it to finish.
  2. If a CI job was cancelled or a laptop lost connection mid-apply, the lock can stay behind.
  3. Confirm nobody is running, then: terraform force-unlock 6f1c2e9a-... (the ID from the message).
  4. Run terraform plan to see if the interrupted apply left anything half-done, and apply again to finish.
  5. In emergencies only, -lock=false skips locking; avoid it, because two applies at once can corrupt state.

Where the lock lives

BackendLock mechanism
AWS S3Native S3 lock file with use_lockfile = true (Terraform 1.10+); older setups use a DynamoDB table
Azure StorageBlob lease on the state blob
Google Cloud StorageLock object in the bucket
HCP Terraform / Terraform CloudWorkspace lock, visible in the UI
Local fileA .terraform.tfstate.lock.info file next to the state

Prevent it

  • Run Terraform from one pipeline per state, not from laptops, for shared environments.
  • Use a pipeline concurrency limit (one job per environment at a time).
  • Use -lock-timeout=5m so short overlaps wait instead of failing.
  • Split large states (network, data, apps) so teams do not block each other.

Questions

Is force-unlock dangerous?

Only if another apply is really running. Then two runs could write state at once. Always confirm the lock owner is gone first.

Why do I need locking at all?

Without it, two people applying at the same time can overwrite each other's state and leave Terraform unaware of real resources.