Pcornel
Automation · Terraform / OpenTofu

State Locking

Cheat sheet · https://pcornel.dk/topic.php?topic=5451

Back to the Topic

Answer

Terraform/OpenTofu state locking prevents concurrent state-writing operations when the selected backend supports a locking mechanism.

Remember

  • Lock success ≠ exclusive infrastructure ownership; out-of-band API changes and other states can still modify the same remote systems.
  • Terraform/OpenTofu command success ≠ target workload health; provider operations and application acceptance are separate proof boundaries.
  • The same repository ≠ same run when binary, provider/module versions, backend/workspace, variables, credentials or lock selections differ.
  • Treat Terraform and OpenTofu as separate implementations: verify behavior against the pinned tool and dependency versions rather than assuming interchangeability.

First checks

  • Lock table/lockfile/blob lease configured — locking
  • terraform plan (concurrent attempt shows lock) — test
  • terraform force-unlock <id> — emergency only

Verify in this order

run → lock → change → unlock

Where it usually breaks

Lock success ≠ exclusive infrastructure ownership; out-of-band API changes and other states can still modify the same remote systems. The proof boundary ends where provider/state evidence stops and target-domain acceptance begins.

Configuration/input → graph/state refresh → plan → provider API request → provider terminal result → resource read-back → effective service state → workload.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5451

Confirmation

Confirm action

Continue?