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.
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
- Check whether a pipeline or teammate is running Terraform on the same state. If yes, wait for it to finish.
- If a CI job was cancelled or a laptop lost connection mid-apply, the lock can stay behind.
- Confirm nobody is running, then:
terraform force-unlock 6f1c2e9a-...(the ID from the message). - Run
terraform planto see if the interrupted apply left anything half-done, and apply again to finish. - In emergencies only,
-lock=falseskips locking; avoid it, because two applies at once can corrupt state.
Where the lock lives
| Backend | Lock mechanism |
|---|---|
| AWS S3 | Native S3 lock file with use_lockfile = true (Terraform 1.10+); older setups use a DynamoDB table |
| Azure Storage | Blob lease on the state blob |
| Google Cloud Storage | Lock object in the bucket |
| HCP Terraform / Terraform Cloud | Workspace lock, visible in the UI |
| Local file | A .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=5mso 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.