# Terraform: "Error acquiring the state lock" means wait, then investigate

## What you are seeing

```
Error: Error acquiring the state lock

Error message: ConditionalCheckFailedException: ...
Lock Info:
  ID:        abc123
  Path:      myapp-terraform-state/dev/terraform.tfstate
  Operation: OperationTypeApply
  Who:       deploy-bot@ci-runner-4
  Version:   1.9.0
  Created:   2026-09-26 03:10:00 +0000 UTC
```

State locking prevents two writes from corrupting the state file. This error means another process holds the lock. Reads (plan, refresh-only) generally do not need the lock; writes (apply, state mv) do.

## First response

1. Read the Lock Info. `Who` and `Created` tell you whether this is a live run or a corpse. A lock created two minutes ago by your CI pipeline is a live run: wait.
2. If it is your own pipeline, let the other run finish. Retrying apply in a loop does not help and can pile up queued runs.
3. Only `terraform force-unlock [lock-id]` when you have confirmed the holder is dead: crashed CI job, killed terminal, no terraform process running anywhere with that lock ID.

## Rules for agents

1. Never force-unlock because you are impatient. Two writers with one state file is how state gets corrupted.
2. `terraform plan -lock=false` and `terraform apply -lock=false` disable locking entirely. This is a loaded gun: only for broken-lock emergencies you fully understand, never as a default.
3. Recurring stale locks point at infrastructure: CI jobs that get SIGKILLed, runners that die mid-apply. Fix the runner lifecycle, not the symptom.
4. After any force-unlock, run `terraform plan` and read it fully before applying. If the killed run half-applied, the plan shows it.
