ADR-0021: The commit stays out of state, and drift is judged from the plan#

  • Status: accepted. In force since 25 November 2026 (see Current status).
  • Date: 2026-11-25

Context#

The review of 24 November 2026 found that merged is not applied, and nothing notices (finding 5). Three pull requests had merged since the last apply, and the website's DNS table, generated from state, still described a removed CAA iodef record. The fix it proposed was a weekly tofu plan -detailed-exitcode that opens an issue when the plan is not empty.

Two things stop a plan of this root from ever being empty.

  1. The commit SHA is in state. CI passed github.sha as commit_sha. It

became the edge API Lambda's COMMIT_SHA environment variable and the commit field of the site_facts output. Every commit changes both, so every plan showed one resource to change and one output to change, even for a documentation-only commit. The same value was what every page footer reported as "built from", so a documentation-only deploy, which does not apply, was stamped with the commit of the last apply instead of its own (finding 6).

  1. Every plan reads the live homepage probe. The site_is_reachable_and_hardened

check in terraform/environments/prod/checks.tf contains a data "http" block. OpenTofu plans a data source nested in a check block as a read during apply on every plan (read_because_check_nested), and counts that read as a change: -detailed-exitcode returns 2, and the summary is "Plan: 0 to add, 0 to change, 0 to destroy", never "No changes". This was confirmed in OpenTofu 1.13.2's source (Plan.CanApply treats any action other than no-op as a change) and with a scratch configuration holding only such a check, which exited 2. The review did not find this; it was hidden behind the first.

Constraints: the plan must use the read-only plan role (ADR-0006); a check must be able to fail, and an error must never read as a pass (principle 2); the website must not misstate what it was built from (principle 1); no new dependency, and no live probe removed to make a number come out right.

Decision#

  1. The site build takes the commit from the run that builds it.

site/build.py --commit is set to GITHUB_SHA by site-deploy, and the deploy refuses to publish unless the footer names that commit. It accepts only a full 40-character commit ID, or the literal local for a local build. site_facts no longer has a commit field. The commit is not a fact about the infrastructure, so it does not belong in state.

  1. The edge API identifies its source, not a commit. /api/whoami drops

site.commit and reports site.handler_source: the Git blob ID of the handler file, computed by the handler at start-up exactly as git hash-object does. It changes only when the handler changes, which is also the only time the Lambda's code changes in state. git log --find-object=<id> finds the commits that contain it. The commit_sha variable is removed from the module and the root.

  1. A weekly workflow, drift-detection, plans main against production

with the plan role, -lock=false and -detailed-exitcode, and saves the plan. scripts/drift-verdict.py reads tofu show -json of it, with the exit code, and returns one of three verdicts:

    • clean: nothing would change except check-block reads. The open

drift issue, if any, is closed.

    • drift: a resource or a root output would change. One issue labelled

drift is opened, or commented on, and the run fails.

    • error: the plan failed (exit 1), or the job did not finish, or the

plan contains anything the script cannot account for, or the exit code and the contents disagree. The issue is opened or commented on, saying drift is unknown, and the run fails. An error never closes the issue.

The only thing ignored is a read of a data resource whose reason is read_because_check_nested. Any other deferred read means something it depends on would change, so it counts.

  1. The issue is written by a separate job holding only issues: write; the

job that holds AWS credentials cannot write to GitHub. The account ID and the alert address are redacted from the report first, because log masking does not reach an issue. The JSON plan, which holds sensitive values in clear, never leaves the plan step.

  1. No trust change. A scheduled run and a dispatch from main carry the

subject …:ref:refs/heads/main with no environment, which the plan role already trusts. The workflow names no environment and refuses any other branch before it asks AWS.

The schedule is Mondays at 04:41 UTC. GitHub starts scheduled runs late, by 4 to 12 hours in the review's sample, and on a private repository there is nothing to tune. A weekly check that arrives on Monday afternoon instead of Monday morning loses nothing.

Alternatives considered#

Leave the commit in state and filter it out of the verdict. Teaches the verdict to ignore an attribute that changes on every commit, so a real change to that attribute would also be ignored. And it leaves the footer wrong for documentation-only deploys, which is the other half of the problem.

A content hash of the handler, set as an environment variable by OpenTofu (the zip's output_base64sha256). Stable, but it is the Lambda describing its code through state, one step removed from the code itself, and it is not a Git object, so it cannot be looked up in the repository. Computing the blob ID at start-up reports what is actually running.

Drop the identifier from the API entirely. Simplest, and defensible, but "what is running?" is a fair question for an endpoint that exists to show its visitors what the edge sees, and the blob ID answers it at no cost in state.

Remove the data source from the check block so the plan can be empty, and leave the homepage to dns-health. Removes a live probe from every plan and apply to make a number come out right, which CLAUDE.md forbids. The plan's check is the only probe that runs immediately after an apply.

Trust -detailed-exitcode and grep the summary for "0 to add, 0 to change, 0 to destroy". Misses output changes, which are exactly the unapplied-main case (the stale DNS table), and matches text whose wording is not a contract.

tofu plan -refresh-only. Reports changes made outside OpenTofu but not merged code that was never applied, which was the finding.

A third-party drift service (Spacelift, env0, driftctl). driftctl is no longer maintained; the services need a credential to the account and are a dependency to justify (principle 5) for a check that is one plan and one script.

Daily instead of weekly. Drift here comes from merges, which the owner makes and can follow with an apply, so a day's delay costs little, and a daily issue comment would be noise. The plan is also the most privileged scheduled thing CI does (account-wide ReadOnlyAccess); running it seven times as often buys little.

Consequences#

Positive:

  • A documentation-only change plans as clean. The first plan that says "drift"

means something.

  • An unapplied merge or a change made by hand is reported within a week, in an

issue, instead of when someone happens to notice the website.

  • Every page footer names the commit it was built from, including

documentation-only deploys.

  • The error path is tested: 20 unit tests (make test-drift) cover clean,

drift and every error case, and the workflow's simulate_failure input lets the owner see a live failure open the issue and fail the run.

Negative:

  • The plan role is now used on a schedule, not only when someone opens a pull

request: one more time each week that a pinned third-party Action runs beside a token for an account-wide read-only role.

  • scripts/drift-verdict.py depends on the shape of OpenTofu's JSON plan and on

the name of one action reason. A change to either makes the verdict "error", not "clean", by design, but it would need fixing.

  • The verdict ignores every check-nested read, including a future check

added with a data source. That is the intent, but it means a check-nested data source can never itself be reported as drift.

  • /api/whoami's site.commit field is gone; anything reading it gets nothing.

The site's own script does not read it.

  • The first apply after this change updates the edge API Lambda in place

(environment variable removed, code changed) and removes an output field.

Neutral:

  • Changes made outside OpenTofu that the configuration would not undo are

listed in the report as notes, not as drift.

  • The run summary shows "Plan: 0 to add, 0 to change, 0 to destroy" on a clean

week. That is OpenTofu's wording for a plan whose only action is the check read.

Revisit when#

  • OpenTofu stops counting check-nested reads as changes, so

-detailed-exitcode alone means what it says. Then the script can go.

  • The repository goes public and terraform-apply runs on merge again

(ADR-0006). Unapplied merges then stop being the main source of drift, and the schedule can be relaxed or kept for changes made by hand.

  • Drift is found more often than monthly, which would mean something other than

merges is changing production.

Current status#

25 November 2026, before the apply: not yet applied. The edge API Lambda still had COMMIT_SHA, site_facts still had commit, and no drift run had happened.

25 November 2026, later: in force. The steps in the drift runbook were followed in order. Before the apply, drift detection reported exactly the expected two changes (the edge API Lambda and the site_facts output) and opened an issue; it was the first use of the plan role from main outside a pull request, and AWS accepted it. terraform-apply changed only that Lambda, with no failing check. /api/whoami then reported the handler's blob ID, matching git hash-object on main, and the footer named the applied commit. The next drift run was clean and closed the issue. A run with simulate_failure failed and opened an error issue, and the following clean run closed it. The first scheduled run is still to come.

That first run also noted six DNSSEC probe resources as changed outside OpenTofu, without saying which attributes. Pull request #29 makes the report name them, so it can be seen whether they are values AWS maintains itself.

Built 2026-11-25 from commit 33bfabf6a27d4baeecf228c31bd5d636a3965070. This page was generated from the same source that provisions the infrastructure it describes.