ADR-0025: Apply only the plan that was reviewed#

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

Context#

The review of 24 November 2026 (finding 15) found that the plan reviewed is not the plan applied. terraform-apply planned and applied in one job: it applied its own saved plan, so the apply matched that plan, but nobody could read the plan before it took effect. bootstrap-account showed a plan in a first run and applied in a second, but the second run planned again and applied whatever it found, which need not be what the first run showed.

The control that should cover this is a required reviewer on the prod and bootstrap environments. GitHub Free does not offer one for private repositories, so today the person who dispatches the workflow is the approval (ADR-0006, "Current status"), and they approve without seeing what they approve. The repository stays private until the owner has reviewed it as it stands (roadmap).

Constraints:

  • A plan file holds sensitive values in clear, including the alert address

and every ARN, which carries the account ID. It must not be uploaded or kept where others can read it (ADR-0011); a public repository's artifacts are readable by anyone signed in.

  • No new dependency, secret, key or monthly cost

(principle 5, principle 7).

  • A check that cannot fail is worse than none

(principle 2).

Decision#

  1. **Each apply takes two dispatches, and the second applies only the plan the

first showed.** Both workflows take a plan_digest input, empty by default.

    • Empty: plan only. The run plans, writes the plan and its digest to

the run summary, and changes nothing.

    • Given: apply. The run plans again, computes the digest of its own

saved plan, and applies that saved plan only if the digest is the one given. Otherwise it fails and applies nothing.

  1. The digest is a fingerprint of what the apply would do.

scripts/plan-digest.py hashes, with SHA-256, a canonical JSON document of: the root (prod or bootstrap); the commit planned; and from tofu show -json, every resource change, every change made outside OpenTofu that the apply would record, every output change, and whether the plan is complete and applyable. Fields that do not describe the apply (timestamp, prior_state, configuration) are left out; the commit pins the configuration. So the digest changes if main moves, the state changes, AWS changes, or the plan would do anything differently. It refuses an errored, incomplete or unapplyable plan, and an expected digest that is not 64 hexadecimal characters.

  1. No plan file leaves the runner. plan.json is fingerprinted and

deleted; nothing is uploaded. The second run proves its plan is the reviewed one instead of fetching it.

  1. terraform-apply's plan-only run uses the read-only plan role, with no

environment and no lock, like the pull-request plan and drift detection. It never enters prod, so a plan-only run cannot hold a role that writes. Its summary takes out the account ID and the alert address explicitly, rather than relying on log masking reaching the summary. The apply run uses the apply role in prod, as before, and only it can deploy the website.

  1. bootstrap-account keeps one job, with the seed's bootstrap role in

the bootstrap environment for both runs, as before. The apply tick box is replaced by plan_digest. Its plan text is unchanged.

  1. The seed is out of scope. scripts/seed.sh applies in three steps,

each planned only once the step before it has applied (targeted resources with local state, a state migration, then everything). No single plan covers it. It runs once per account, with a temporary user, and the seed-account workflow already plans first and applies on a second dispatch.

  1. It is tested. make test-plan-digest, in make check and in CI, tests

the script, and reads both workflows to assert the following:

    • only the apply job applies or enters prod, and only with a digest;
    • the gate sits between plan and apply, and failing it stops the job;
    • the saved plan is what is applied;
    • the digest reaches scripts only through the environment;
    • plan.json is deleted and nothing is uploaded;
    • the plan-only run is read-only.

Each test was shown to fail by reintroducing the fault it covers.

Alternatives considered#

Upload the saved plan as an artifact and apply that file. The most direct form of "apply what was reviewed", and OpenTofu refuses a stale plan by itself. It lost on the plan file's contents: the alert address and the account ID in clear, in an artifact any reader of the repository can download, and any signed-in user once it is public. Encrypting it needs a key: a new secret for the owner to manage, or a KMS key, which costs money and would itself need to be trusted by both roles.

OpenTofu plan encryption. The same key problem, and it would start on an item the radar holds under Assess (state encryption) for a narrower reason than its condition.

Wait for the repository to go public, and use required reviewers. That is the real gate, and nothing here stops it being adopted. But going public is on hold until the owner's review, and the deploy path ranks second in the principles. Two dispatches cost a minute; an unread plan could cost the domain.

Pause one run between plan and apply. GitHub offers no pause without environment protection rules, and those are what GitHub Free lacks for private repositories. A job that waits on something else (an issue comment, a polling loop) would hold the apply role while it waited.

Compare a summary of the plan (addresses and actions only) instead of the full changes. It would apply a plan whose values differ from the one read: the same update, to a different value.

Make the plan-only run use the apply role, so both plans come from the same role. It would put a role that can write into a run that only reads. Both roles see the same account, and the configuration uses only the account ID from the caller's identity, so the two plans should be identical. If they ever are not, the apply refuses, which is the safe direction.

Consequences#

Positive:

  • Nothing is applied that was not shown first, in full, in a run summary.
  • A digest is good for one commit, one state and one root. If anything moved

in between, the apply refuses and says so; it never applies the newer plan in its place.

  • A plan-only run of terraform-apply holds no role that can write.
  • No plan file, secret, key or cost is added.
  • 39 tests (make test-plan-digest) keep it so.

Negative:

  • Every apply is two dispatches and a copied digest, about a minute more.
  • Reading the plan is possible, not enforced: the digest proves a plan-only

run showed this plan, not that anyone read it. Only a required reviewer makes the review itself a control.

  • A refresh can change the digest without any change to the configuration, for

example an attribute AWS updates by itself, or a resource changed outside OpenTofu. Then the apply refuses and the owner plans again. The longer the wait between the two runs, the likelier this is.

  • The two plans of terraform-apply come from different roles. If they ever

differ in something role-dependent, every apply refuses until that is fixed. This was reasoned about, not observed: the first real use will show it.

  • make test-plan-digest reads the workflows as text, as the other workflow

tests do; the gate steps' shell was also run once against a stub tofu.

  • bootstrap-account's plan text still goes to the summary as before,

relying on GitHub's masking of the AWS_ACCOUNT_ID secret there.

Neutral:

  • The digest is printed in run summaries. It is a hash over the whole plan and

does not reveal the values in it.

  • -auto-approve is not used anywhere: applying a saved plan needs no

approval prompt.

Current status#

25 November 2026, at merge: merged in PR #37; the workflows change on the next dispatch, with nothing to apply. The first real use is the verification: a plan-only run of each workflow, then an apply run with its digest, and an apply run with a wrong digest that must refuse.

25 November 2026, later: in force, after the fix in PR #38 (see Status notes). All from main at 43b5a34:

  • terraform-apply run 10, plan only: the read-only plan role planned

0 to add, 0 to change, 0 to destroy; the apply and deploy jobs were skipped; the digest was logged.

  • terraform-apply run 11, with that digest: the apply role's plan in prod

matched it, the saved plan was applied (no changes), and the website redeployed. This also settles the Negative consequence about the two roles: their plans of the same commit and state are identical.

  • terraform-apply run 12, with the digest's last character changed: refused

with "not the plan that was reviewed"; nothing was applied and the website was not deployed.

  • bootstrap-account run 11, plan only: "No changes"; the apply step was

skipped; the digest was logged. Run 12, with that digest: matched and applied, with no changes.

Status notes#

  • 2026-11-25, erratum, before the decision was in force. Decision 2 says

the digest covers every resource change. One kind is now left out: the read of a data source nested in a check block (action_reason read_because_check_nested), the same rule scripts/drift-verdict.py uses. The first plan-only run of terraform-apply (run 9, from main at the merge of PR #37) showed that the homepage probe in checks.tf is read during the plan, with the live response, whose Date and X-Amz-Cf-Id headers differ on every request. Hashing it would have made every apply refuse. Leaving it out cannot let a different apply through: a data source in a check block cannot be referenced outside it, and a failing check is a warning. The Alternatives section's claim that the two plans "should be identical" assumed this read was deferred to the apply; it is not. Run 9 also showed the digest was written only to the run summary, so it is now in the log as a notice as well. make test-plan-digest has 43 tests, and the new ones were shown to fail with the old behaviour.

Revisit when#

  • prod and bootstrap gain required reviewers (the repository goes public or

moves to a paid plan). A reviewer approving a run that shows its plan could replace the two dispatches, and the apply-on-merge trigger kept in terraform-apply could return.

  • The two plans keep differing for a reason other than a real change, so that

applies refuse routinely.

  • OpenTofu changes the shape of tofu show -json, or adds a field to it that

describes what an apply would do.

  • The seed gains a single-plan apply.

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