Architecture — State Bucket

By Engineering & Security Architecture Team•November 29, 2026•3 min read

L1 bootstrap creates one state bucket for the whole account. Every layer keeps its state there, encrypted on the client before upload. Requirements: SR-INFRA-008 SR-F-12, SR-F-13 and SR-NF-08, and SR-INFRA-009 SR-NF-02.


1. Writers and copies

State bucket: L1 bootstrap, L2 setup nonprod and a site's first setup from their dev containers, and setup-prod.yml and the site's infra.yml promotions from GitHub Actions, write encrypted state to workloads/; state is copied to the retention-locked history/ prefix by state-history-copy.sh on the host after a person's apply, by snapshot-state.sh in infra.yml after each successful apply, and by setup-prod.yml after its apply


2. Layout

<state-bucket>/
  workloads/<module>.tfstate                          live state, one object per root module
  history/<module>/<UTC time>-<digest>.tfstate.encrypted   copies
Prefix Holds Protection
workloads/ The live state of each root module: L1, both L2 roots, and each site’s non-production and production roots No lock and no expiry. Every apply overwrites it, so a lock would block the next apply (SR-INFRA-008 SR-NF-08)
history/ Timestamped copies of each state A retention lock on this prefix only: a copy cannot be deleted or overwritten for the retention period, 30 days by default

The bucket itself:

  • Is private. Its public r2.dev address is turned off, so it is reachable only with a state key pair.
  • Is protected from deletion in code (prevent_destroy), because losing it loses every layer’s state.
  • Is reached through state key pairs limited to this bucket, separate from the tokens that change resources, so rotating one never forces rotating the other.
  • Holds only encrypted objects. State and plans are encrypted with a passphrase per root module, so a key pair alone cannot read any state.

3. How copies are made

Script Runs Covers
state-history-copy.sh On the host, by a person through op run, right after an apply from a dev container The one module just applied
snapshot-state.sh In the site’s infra.yml promotion, after the apply, only if it succeeded Every state that changed
setup-prod.yml In the project-setup layer’s production workflow, after a successful apply The production setup state

No workflow copies state on a schedule: every copy is made by the change itself. Every copy is a server-side copy of the encrypted object as stored, so no script ever decrypts state. A copy is named after the UTC time and a digest of the content, and is skipped when that content already has a copy. Each copy runs inside the promotion that holds the environment’s lock, so it never runs while another apply writes that state.


4. Recovery

When an apply goes wrong or state is overwritten, the last good copy under history/ is still there for the retention period, whoever holds a key pair. Restoring it means copying it back to workloads/ and running a plan that shows the expected changes before any apply.