Interview Prep/Terraform/State Backends and Workspaces

A CI job crashed and the lock remains. When is `force-unlock` acceptable?

AdvancedScenarioState Backends and Workspaces
Answer

Situation read → A stale lock from a killed runner blocks everyone.

What I'd do →

  1. Confirm via the lock info (ID, who, when) and CI that no run is active.
  2. Check the state isn't partially written: compare the latest S3 version and look at logs.
  3. Run terraform force-unlock <LOCK_ID>.
  4. Run plan to verify state and reality agree.

Why → Unlocking while a real apply is running can corrupt state. Verify, then unlock, then re-plan.

Interview tip → With use_lockfile, the lock is an S3 object, which you can also inspect and delete.

All Terraform questions Roadmap: Terraform in production

More on State Backends and Workspaces