Back to Terraform

Backend Bootstrap and the S3 Locking Migration

November 6, 2026 Wasil Zafar 32 min read

Rehearse backend creation, native lock adoption and recovery without losing the state owner

Table of Contents

  1. The Backend Cannot Depend on Its Own Uncreated Storage
  2. Separate Bucket, State Object, Lock Object and Encryption Permissions
  3. Coordinate CLI Versions Before Switching Lock Mechanisms
  4. Rehearse Init Migration with Snapshots and One Writer
  5. Prove Lock Contention and Recover Only a Stale Lock

The Backend Cannot Depend on Its Own Uncreated Storage

The circle is made of ownership, not tooling. Terraform needs the bucket before it can read its state, yet the bucket is itself a resource Terraform would normally create. One root cannot both hold the state and build the place where the state lives. Trying produces an init with nowhere to write, or, worse, a destroy that removes the bucket and the record of everything it managed.

The backend cannot host itself

Terraform needs the bucket before it can read state, but the bucket is a resource Terraform would create. One root cannot do both: init has nowhere to write, or a destroy takes the bucket and the record with it. Split bootstrap from workload roots.

The way out is a second root with a shorter life and a longer memory. A bootstrap root creates the storage, hands out access, moves its own state into the new bucket, and then runs only when the storage itself must change. Workload roots consume what it made and never administer it.

Version baseline. Behavior here was checked against Terraform CLI 1.17.1 and the S3 backend documentation for the v1.17 line, which is also where the DynamoDB locking path is marked deprecated.

Four things belong in the bootstrap root, and nothing else. The bucket with versioning, encryption and public-access blocking; the customer-managed key and its policy; the bucket policy that names who may read, write and restore; and the break-glass role that can bring a previous version back. A root that also creates VPCs or application roles has stopped being a bootstrap root.

Local state is the seed, not the destination. The first apply runs from a working directory with no backend block, which keeps the plan readable and the blast radius obvious; that run creates the bucket, the key and the policies. The backend block is added afterwards, and one init moves the local state into a platform-only key under a bootstrap prefix.

Local state is the seed

Start without a backend block, read the first plan locally, then add the backend and run one init to migrate. That keeps the first blast radius visible and gives you a known local copy if the migration fails.

That migrated key is production state. It records the bucket policy, the key policy, the role trust and the versioning configuration, so losing it is the same class of accident as losing a workload's state. The difference is that this one explains how recovery works.

Recovery is a named role, not a helpful administrator. The role lives in the state account, is assumable by on-call through a documented approval, may read noncurrent versions and decrypt with the state key, and may write a chosen version back. It may not create buckets, change the key policy or edit the bucket policy, because those are the permissions that caused the incident being recovered from.

Two guardrails are worth the configuration. A bucket policy that denies bucket deletion to every principal that cannot rewrite the policy itself, and a lifecycle rule that keeps noncurrent versions longer than your detection time. The policy prevents the accident; the retention survives it.

If the bucket already exists, adopt it. A platform team that already runs a state service does not need a second one. The bootstrap root imports the bucket, the key and the role, and the plan after the import must be empty; a plan that offers to create a bucket you can see in the console means the import was skipped.

Two identities are enough, and they should not be the same one. The administrator that creates the bucket exists for an afternoon; the role the bootstrap root uses to write its own state afterwards is narrower and long-lived. Keeping them apart means a re-run of the bootstrap root cannot quietly re-policy the bucket it is only supposed to be recording.

Figure 1 shows the order, including the one edge that is not a build step.

The Backend Cannot Depend on Its Own Uncreated Storage
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["bootstrap root
local state on a runner"] --> B["Create bucket
versioning, SSE-KMS, public access blocked"] B --> C["Bucket and key policy
deny bucket deletion, name the recovery role"] C --> D["Break-glass role
read noncurrent versions, write one back"] D --> E["Add backend block
init migrates bootstrap state"] E --> F["bootstrap/terraform.tfstate
platform-only key"] F --> G["Publish bucket, region and role ARNs
to the platform catalogue"] G --> H["Workload init
partial backend configuration"] B -. "key policy rewritten or bucket deleted" .-> R["Recovery owner copies a noncurrent version
then plans against restored state"] R --> C classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,C,G primary; class B,E secondary; class D warn; class F,H ok; class R danger;

Read the dashed edge as a permission, not a step. Recovery is the only way back from a deleted bucket or a rewritten key policy, and it ends in a restore plus a plan, not an apply that rebuilds the bucket. A recovery that starts by re-creating the bucket has already lost the objects that proved what was there.

Figure 2 separates the three authorities the flowchart compresses into one bucket.

Bootstrap root, state bucket and the three authorities over it The bootstrap root starts with local state, creates the bucket, key and policies, then migrates its own state into a bootstrap key. Inside the bucket sit the bootstrap key, a workload state key and its lock object. Three authorities are separate: the bootstrap admin that creates and re-policies, the recovery owner that reads noncurrent versions and restores one, and the workload writer that reads and writes one key and its lock object. One bucket, three kinds of authority Create once, restore rarely, write often. Different principals for each. bootstrap root starts with local state create bucket, key and both policies add the backend block migrate once bootstrap state leaves the runner runs by hand, from a protected branch not in the workload pipeline S3 state bucket versioning, SSE-KMS, public access blocked bootstrap/terraform.tfstate how the bucket was made network/prod/terraform.tfstate overwritten in place terraform.tfstate.tflock created, read, then deleted Object versions are the recovery set. No principal may delete the bucket. The key policy gates version reads. bootstrap admin create bucket, key, policy re-policy is break-glass no workload access recovery owner read noncurrent versions decrypt with the state key write one version back workload writer one key, one lock object no version listing no bucket administration Bootstrap state records the bucket, and the bucket holds the bootstrap state. Only versioning plus a restore-tested role breaks that tie when the policy is wrong.

The handoff is a record, not a data source. The bootstrap root publishes the bucket name, region, key prefix and role ARNs to a platform catalogue that people and pipelines read. Workload roots receive those values as backend configuration; they do not read the bootstrap root's state to discover them, because that would grant every workload read access to the recovery record.

The bootstrap root's destroy path is a documented procedure. It empties versions deliberately, removes the deny policy last, and runs with an approval that names the bucket. A pipeline able to destroy the bootstrap root can destroy the audit trail of every other root in the estate.

Separate Bucket, State Object, Lock Object and Encryption Permissions

Four objects, four different questions. The bucket asks who may list and administer; the state object asks who may read and overwrite; the lock object asks who may create and delete; the key asks who may decrypt. A policy that answers all four with one grant answers none of them.

Listing is the permission people forget. Terraform lists the prefix before it reads the key, so a role with object read and write but no bucket list fails during init with an error that names the bucket, not the object. Scope the list with a prefix condition on the key prefix itself, so the grant cannot enumerate the rest of the bucket.

The lock key is the state key with a suffix. Terraform writes the lock object beside the state object with a .tflock suffix, which is why a prefix-wide delete grant is far broader than the mechanism needs.

The state object needs read and write, not delete. Terraform overwrites the state object and never removes it, so delete on the state key is not part of a normal lifecycle. The exception is workspace deletion, which removes that workspace's state object; a root that uses workspaces needs delete on the workspace paths and not on the default key.

The lock object needs all three verbs, and only there. Creating the lock is a conditional write that fails when the object exists, releasing it is a delete, and inspecting it is a read. Grant delete on the lock key alone; a delete grant on the whole prefix turns an ordinary cleanup script into a state-loss incident.

Encryption adds a fifth permission that is easy to miss. With a customer-managed key, every read and write of state and lock objects needs encrypt, decrypt and data-key permissions on that key. The lock body is encrypted too, so a principal that can list the lock but not decrypt the key sees an object it cannot interpret.

Versioning is the recovery mechanism, and its retention is the control. Noncurrent versions are what a restore reads, so a lifecycle rule that expires them in seven days gives you a seven-day recovery window whether or not that matches your detection time. Write the number down and keep it beside the runbook.

Public access blocking and a TLS-only deny are cheap. Neither affects Terraform, both remove whole classes of accidental exposure, and both belong to the bucket rather than to each workload's policy. They also survive a workload role that is later widened by mistake.

Least privilege has an asymmetry worth reviewing on its own. Write access to state is destructive by nature because the object is overwritten in place, while delete access to the lock is routine hygiene. Reviewing "can this role write state" without reviewing "can it remove a lock it did not create" misses which of the two failures is recoverable.

Verify the two grants independently. Simulate the workload role against the lock key for create and delete, then against the state key for delete, and expect allow for the first and deny for the second. A single simulation of "can this role run Terraform" says nothing about the blast radius when its credentials leak.

The backend role and the provider role are separate settings. A root can read and write state through a narrow state role while creating infrastructure with a broader workload role, because the backend's assume-role applies to backend calls only. That split is what keeps a workload credential from also being a state administrator.

Figure 3 follows one write through those grants and shows where each missing permission lands.

Separate Bucket, State Object, Lock Object and Encryption Permissions
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    W["writer starts a plan or apply"] --> L{"ListBucket on
the state prefix?"} L -- "no" --> E1["init fails
access denied names the bucket"] L -- "yes" --> G{"GetObject on
the state key?"} G -- "no" --> E2["plan fails
state cannot be read"] G -- "yes" --> K{"Decrypt with
the state key?"} K -- "no" --> E3["object present, body unreadable
KMS access denied"] K -- "yes" --> C["conditional create
on the lock key"] C -- "already exists" --> E4["lock reported as held
with holder and start time"] C -- "created" --> P["state written
new object version"] P --> D{"DeleteObject on
the lock key?"} D -- "no" --> E5["apply already wrote state
unlock fails, lock remains"] D -- "yes" --> OK["lock released
the next writer proceeds"] E4 --> Q{"live writer confirmed?"} Q -- "yes" --> WAIT["wait, cancel or escalate"] Q -- "no" --> F["force-unlock with the recorded ID"] F --> W classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class W,G,P primary; class L,K,C,D,Q secondary; class OK,F ok; class E1,E2,E3,E4,E5 danger; class WAIT warn;

The conditional create is the whole lock. When two writers race, one create succeeds and the other receives a precondition failure that Terraform reports as a held lock with the holder's identity and start time. Everything around it — the file name, the delete on release, the force-unlock command — exists to support that single atomic decision.

The quiet failure is at release, not at create. A role that can create the lock but not delete it writes state correctly, then fails to unlock, leaving contention whose holder has already finished. That looks like a concurrency bug and is actually a missing permission on one key.

Cross-account access belongs in the bucket policy, not in a wildcard. A workload role in another account can be named as the principal for one prefix, with the lock key listed separately. The alternative, granting the whole bucket to the workload account, moves the boundary from an object path to an account, which is exactly the boundary you were trying to keep narrow.

Coordinate CLI Versions Before Switching Lock Mechanisms

The lock setting is configuration, and configuration drifts faster than binaries. With a partial backend block, the bucket, key and lock settings arrive from a per-environment file at init time. Two runners can therefore execute the same commit against the same key with different lock settings, and nothing in the plan shows the difference.

Two arguments carry the switch. use_lockfile turns on the native lock object; dynamodb_table names the legacy table, and setting both is the documented migration window rather than a permanent arrangement.

Native locking arrived as experimental in 1.10; by 1.17 the lockfile is the documented S3 mechanism and the table path is marked deprecated. The flag is unset by default, so upgrading the CLI changes nothing until the backend configuration opts in. The version floor matters because an older CLI rejects the unknown argument at init, which is a safe failure but still an outage for that runner.

DynamoDB locking is deprecated in the current documentation and slated for removal in a future minor version. It still works, and the S3 backend still accepts both settings at once, explicitly to support migration from older CLIs. That simultaneous setting is not a permanent design; it is the window in which you move.

Two locks are safer than one and twice as breakable. A run with both settings acquires both records, so either a stale table item or a leftover lock object blocks the next apply. That is the correct trade during a cutover and the wrong trade forever, because it doubles the ways a cancelled runner can stop a pipeline.

The dangerous writer is the one whose configuration omits both settings. Such a writer takes no lock, ignores both records, and overwrites state with whatever it planned. It does not look broken, it produces a green apply, and it is usually a scheduled job, a vendored CLI inside a container image, or a laptop whose backend file was never updated.

Inventory writers by configuration, not by headcount. Search every repository, CI variable set and runner image for the backend arguments, then list the principals that can write the key. The two lists should agree; a principal with write access that appears in no configuration is a writer you cannot schedule around.

The version constraint is the cheapest gate. Pinning the CLI in the root makes an old runner stop on the version check before it reaches the backend, which converts a silent no-lock write into a failed pipeline. It does not help the runner that never reads this root's configuration at all, which is why the inventory comes first.

Managed run platforms add a version you do not control. A hosted runner or an internal Atlantis deployment may bundle its own CLI, upgrade on its own timetable, or pin a version per workspace. Ask for the version each agent reports, not the version in your repository, and treat a bundled CLI as a separate writer.

Saved plans carry the backend settings they were created with. A plan produced before the switch records the old lock configuration and applies it unchanged; after the table is gone that apply fails, and before it is gone it takes the old lock. Discard saved plans across the switch instead of carrying them through it.

The table reads left to right: what the writer is configured with, what it actually acquires, and what that does to everyone else.

Writer configurationLock it acquiresEffect on a writer using the other mechanismAcceptable when
Native lockfile, CLI 1.10 or laterConditional create of the lock object beside the state keyA table-only writer never reads the lock objectEvery writer is on 1.10 or later, which is the target state
Table only, any CLIItem in the table, plus the digest item for the same pathA lockfile-only writer never reads the tableLegacy writers remain, before the flag reaches the backend file
Both settings, CLI 1.10 or laterBoth records in the same runEither record blocks the other writerThe cutover window and the soak that follows it
Native lockfile, CLI older than 1.10None, because init rejects the unknown argumentFails closed with no state writtenNever, but it is the failure you want
Neither settingNoneTwo writers overwrite each other, and the last write winsOnly for a key nobody else can reach
Table setting removed, saved plan keptWhatever the plan recorded at creationThe plan applies under the old settingsNever, discard plans across the switch

Rows four and five are the ones to design against. An argument the CLI does not recognize fails closed and is recoverable; a configuration that names no lock fails open and is not. Every step that follows exists to keep the estate in the first category.

Figure 4 compares the order that keeps the failure safe with the order that hides it.

Two orders for upgrading writers and switching the S3 lock mechanism The upper lane upgrades every writer first, then enables both lock mechanisms for a soak, then removes the table setting and finally the grants. Each step is reversible and a stale record blocks the next run. The lower lane enables the lockfile before older writers are upgraded, creating a window where a writer with no lock setting overwrites state with a green apply. The same three changes, in two orders Only one of them keeps every intermediate state fail-closed. SAFE ORDER 1. Upgrade every writer CLI 1.10 or later no setting changed yet 2. Enable both mechanisms lockfile and table soak one pipeline cycle 3. Remove the table setting lockfile only still reversible 4. Drop grants then the table last, not first At every step, a run either takes a lock or refuses to start. Rollback is a file revert. UNSAFE ORDER 1. Enable the lockfile in one backend file writers still on old CLIs Window: no shared record old writer takes no lock green apply, silent overlap 2. Upgrade the rest after the overwrite state already diverged 3. Restore from a version not from a plan The window is invisible in the plan: both runs succeed, and only one of them locked anything. The configuration file, not the binary version, decides which lock a writer honors.

The order is upgrade, then overlap, then removal. Upgrade every writer to a CLI that understands the flag, set both mechanisms and soak, then remove the table setting, and only later remove the grants and the table. Each step is reversible until the last one, which is the point of putting it last.

Two flags help during the change and one is a trap. A lock timeout lets a waiting run back off and retry instead of failing instantly, which suits CI during a cutover. Disabling the lock removes the only signal the exercise is trying to prove and should never appear in a cutover pipeline.

Rehearse Init Migration with Snapshots and One Writer

The change itself is a line in a backend file. Everything that makes it safe happens around that line: the freeze, the snapshot, the flags, and the proof that the run afterwards read the same history it read before.

Freeze the writer set first. Set the pipeline concurrency for the affected root to one, pause scheduled drift runs, and confirm that no interactive apply is in flight. The freeze is what turns "one writer" from an intention into a fact you can evidence.

The evidence is three checks, taken at the same moment. A pipeline queue with no running or queued job for the root, an empty lock record under both mechanisms, and a permission list in which every principal that can write the key has a name and an owner. Two out of three is a guess.

Snapshot three things, not one. Pull the state JSON, record the object's version identifier, and note the lineage and serial from that JSON. The version identifier is what a restore actually needs; the lineage is what proves the run after the switch is reading the same history.

Treat the snapshot as a secret with an expiry. It contains every attribute the root manages, so it belongs in an encrypted location with a recorded checksum and a deletion date. A copy in a downloads folder is a second copy of the estate's secrets with no owner.

The init semantics are narrow and worth stating exactly. Changing the lock settings changes the backend configuration, so a plain init refuses to continue and accepts only -reconfigure or -migrate-state. Because the bucket and key did not move, the reconfigure flag is the correct one: it adopts the new settings without copying state.

A migration flag on a same-location change is noise, not caution. It attempts to copy state from the place it already sits, adds prompts and a second credential path, and improves nothing. Use it when the bucket or key moves, and use the reconfigure flag when only the lock mechanism does.

If the location does move, keep both credentials alive. A migration reads from the old backend and writes to the new one in a single operation, so revoking the source role first converts a routine copy into a restore exercise. That ordering trap is independent of which lock mechanism is in play.

Init does not arbitrate between writers. On a reconfigure it only updates the working directory; the first operation that takes a lock is the plan or apply that follows. This is why the freeze must cover the window around init, not only the apply.

The first plan after the switch is the acceptance test. It must acquire the new lock, read the same lineage and serial, and propose no changes. A plan that wants to create resources proves the state was never read, and the correct response is a restore rather than a retry.

Rollback is the same change in reverse, and it needs the table. Revert the backend settings, reconfigure, and plan; the old mechanism works only while the table and its grants still exist. That is the real reason deletion waits, because rollback is a configuration change rather than a rebuild.

Damage is different from rollback. If the state was truncated or replaced rather than merely re-locked, copy the recorded version back onto the key and compare lineage before any push. A push that bypasses the lineage check turns a recoverable overwrite into an unrecoverable one.

Figure 5 places the snapshot, the two init flags and the rollback on one timeline.

Before, during and after the lock-mechanism switch, with the snapshot and rollback path Before the switch the root locks through a DynamoDB table and a snapshot records the state object version, lineage and serial. During the switch both mechanisms are configured and init adopts the new settings without copying state. After the switch the lock object is the only record, and rollback reverts the backend file and reconfigures while the table still exists. A restore path copies a recorded noncurrent version onto the key before any push. One backend file, three states of the world The snapshot is taken before step one and outlives every state below it. BEFORE: TABLE ONLY backend file names the table dynamodb_table = <name> Every run writes an item, then deletes it on release. The lock record lives in another service, with its own grants. Reversible at any time. DURING: BOTH RECORDS both settings in the same file table and lockfile together Init reconfigures, not migrates. No state is copied. A plan proves the same lineage and serial, with no changes. Soak one full pipeline cycle. AFTER: LOCKFILE ONLY the table setting is gone use_lockfile = true One conditional create, one delete. The state key and the lock key sit in the same bucket and policy. One record, one failure point. Table deletion is the last step. Snapshot, taken before step one object version identifier · lineage · serial · checksum · encrypted location · deletion date ROLLBACK revert the backend file, reconfigure, plan needs the table and its grants intact RESTORE copy the recorded version onto the key compare lineage before any push

Canary one root, then move in waves. Pick the root with the smallest blast radius, run the full sequence, and leave it for a soak covering at least one scheduled pipeline cycle. The wave after that is a copy of a known-good procedure, not a second experiment.

Reverse migration deserves one rehearsal, not a design. Going back to DynamoDB needs a table with the documented partition key and the grants restored; it is a rollback path, not a target architecture. Rehearse it once on the canary so the runbook is a transcript rather than a theory.

Record four artefacts and keep them together. The pre-change snapshot with its version identifier, the init output naming the backend, the post-change plan with its exit code, and the rollback result. The next reader should be able to tell which lock was active at each step without asking anyone.

Prove Lock Contention and Recover Only a Stale Lock

A lock you have never seen work is a hope. Contention is the only test that proves the new mechanism is engaged, and it is harmless when it runs on a throwaway key whose state manages nothing that matters.

Design the exercise so both outcomes are boring. The holder should be a run you can kill, the state should be disposable, and the recovery should be a command you have already read once. If the exercise can damage a real environment, it is not an exercise.

Two records mean two failure points. During the overlap window, a stale table item and a stale lock object are independent problems, and clearing one leaves the other blocking. The lab has to show that, or the cutover runbook will tell someone to clear the wrong record.

Staleness is an age, not a feeling. Compare the lock's creation time with the longest apply that root has ever run, then add a margin; a lock older than that with no matching job is a candidate, and a lock younger than that is a reason to wait.

CloudTrail is not evidence unless data events are on. Object-level writes are not recorded by default, so an empty event history usually means nobody enabled the trail, not that nobody wrote. Check the trail configuration before you cite its silence.

Lab

Rehearse the lock migration

Status: design-only. No cloud resources are created by reading this, and no identifier below is real. The exercise needs a disposable prefix, not a disposable environment.

Prerequisites. Terraform CLI 1.17.1, an S3 prefix with versioning and a policy copied from production, one DynamoDB table if you are rehearsing the overlap, two terminals, and a role holding exactly the grants from the permission section.

Setup. One lab root whose only resource is the built-in terraform_data with a local-exec provisioner that sleeps for two minutes, plus a backend file whose key sits under a lab prefix. The sleep is what makes the contention window long enough to observe.

  1. Apply in terminal A and, while the sleep runs, read the lock object's metadata and body. Expect an object beside the state key naming the lock ID, the operation, the holder and the start time.
  2. Plan in terminal B. Expect an error naming the lock ID, the state path, the holder and the creation time, and record all four fields.
  3. Plan again in terminal B with a lock timeout of ten seconds. Expect the same error after the wait, not a silent queue and not a second lock.
  4. Kill terminal A while the sleep still runs. Expect the lock object to remain, because nothing in the mechanism expires it.
  5. Prove there is no writer before touching anything: check the pipeline queue, compare the lock age with the longest apply, confirm the audit trail records object writes, and list the principals that can write the key.
  6. Force-unlock with the recorded ID, then plan. Expect a fresh lock, the same lineage and serial, and no proposed changes.
  7. Repeat steps 1 and 2 with both mechanisms configured. Expect the table item and the lock object to exist together, and expect clearing either one alone to leave the run blocked.
  8. Roll back: restore the previous backend file, reconfigure, and plan. Expect the old mechanism to take the lock and the plan to stay empty.
CheckEvidencePass looks like
Lock engagedlock object metadataobject beside the state key, body names the holder
Contention reportedplan errorlock ID, path, holder and creation time all present
Timeout honouredsecond plansame error after the wait, no silent proceed
Stale lock surviveskilled runlock still present, nothing expired it
Recoveryforce-unlock outputfresh lock, same lineage, empty plan
Dual locktable item and lock objecteither record alone still blocks
Rollbackplan after revertempty plan under the old mechanism

Expected observation. Every failure names the holder, every recovery is a proof followed by one command, and the dual-lock run never proceeds on a single cleared record.

Failure checks. A lock that is never observed means the setting never reached the backend file. A force-unlock attempted before the writer check fails the lab. A rollback that needs a new table means the table was deleted before the soak ended.

Cost. One bucket prefix, a handful of object versions and a short-lived table; the sleep spends runner minutes, not infrastructure.

Cleanup. Delete the lab prefix and its versions, remove the table, and keep the sanitized transcripts rather than the raw ones.

Evidence to keep. The contention error with its four fields, the lock body, the dual-lock observation, the rollback plan, and the inventory of every principal able to write the key.

What the exercise proves, and what it does not. It proves the writer respects the lock, the error names the holder, and the recovery clears the right record. It does not prove that every writer respects it; only the configuration inventory and the independent permission review can say that.