ADR-0023: Decision tests run against the production root, and assert what is derived#

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

Context#

Principle 2 says tests assert decisions, and that a check that cannot fail is worse than none (principles). The review of 24 November 2026 (finding 9) found three ways the tofu test suites could not fail. Each was reproduced on 25 November before anything was changed, by applying a bad configuration and running the whole suite at the main commit.

  1. The suites tested modules, not production. Every run block loaded one

module by its module source. The review said a TLSv1.2_2021 policy or access logging set in terraform.tfvars would pass every test. That part was not quite right. tofu test loads the root's terraform.tfvars and passes a value to a module run when the module has a variable of the same name, so those two edits did fail, by coincidence of names. What nothing could see was the root's own wiring. Each of these passed all 28 tests: enable_access_logs = true or minimum_protocol_version = "TLSv1.2_2021" written into main.tf; enable_email_lockdown = false there, which turns off the null MX, SPF, DKIM and DMARC records; and enable_dnssec = false passed to the zone module.

  1. The published posture held constants. In

module.static_site.security_posture, waf_enabled, ipv6_enabled and origin_public were the literals false, true and false, and origin_access was the literal "cloudfront-oac-sigv4". A test asserted waf_enabled, and the website's posture table publishes all four as if they were facts. Attaching a web ACL to the distribution passed every test, and the website would have kept saying "WAF attached: No". So would loosening the origin access control to no-override signing.

  1. The DMARC assertion matched text, not the tag. regex("p=reject", …)

is satisfied by sp=reject, so p=none; sp=reject, p=quarantine; sp=reject and a record with no p tag at all passed. The health check's grep -q 'p=reject' had the same flaw, and its DKIM check, grep -q 'p=', passed a real, non-empty key as a revoked one.

Constraints: no new dependency; the suite keeps running with mock_provider and no credentials, so it runs on every pull request; and a plan of the production root must not change, because the published facts come from state.

Decision#

  1. A suite plans the production root itself.

terraform/environments/prod/tests/production.tftest.hcl has no module block, so it plans the root as terraform-apply would, with its terraform.tfvars. It asserts the decisions through module outputs: the TLSv1.3_2025 policy (ADR-0004), HTTP/2 and 3, IPv6, no access logs, no WAF (ADR-0009), an origin that cannot be made public and is reached only by OAC signing every request, a signed zone with its probe (ADR-0003, ADR-0020), and the mail lockdown down to the published values (ADR-0008). It also asserts that the website's site_facts.edge is the same object. The module suites stay: they test each module's own behaviour and its off paths.

  1. Production's values have one home. A value in a test file's

variables block silently wins over terraform.tfvars, so the production suite sets only the two values that are kept out of that file (ADR-0011), as placeholders. The root's variables that terraform.tfvars sets lose their defaults, which were copies of the same values. Without the file, the suite stops on a missing variable instead of testing something production does not use.

  1. The posture output is read back from the planned resources. The viewer

policy, HTTP version, IPv6, logging, web ACL, CSP, HSTS and Server-Timing come from the distribution and the response headers policy; origin_access from the origin access control's protocol and signing behaviour. All of them are arguments rather than computed attributes, so they are known at plan time and under mocks. A new module run, posture_follows_the_configuration, checks that the output moves when the configuration does.

  1. origin_public claims only what configuration can show. Whether a

bucket is reachable is not knowable from configuration alone. That it cannot be made public is: all four Block Public Access settings on and ACLs disabled. So origin_public is false only then, and true otherwise. The key keeps its name, so state and the plan do not change, and the website row is relabelled from "Origin publicly reachable" to "Origin can be made public", which is what the value means.

  1. DMARC and DKIM are read as tags (RFC 7489,

section 6.4; RFC 6376, section 3.2). In tofu test, p and sp must each be a whole tag, opening the record or following a semicolon, with whitespace allowed around =; the production suite also requires exactly one record, opening with v=DMARC1. In scripts/health-check.sh, a small tag_value function does the same: one record opening with v=DMARC1, whose p is reject, in any case. More than one record fails, because receivers then apply none (section 6.6.3). The DKIM wildcard passes only as one record with an empty p= (RFC 6376, section 3.6.1); a real key warns, at the same level a missing record already did.

  1. Trivy scans with production's values too. Removing the defaults showed

that trivy config had the same blind spot: it does not load terraform.tfvars, so its TLS rule (AWS-0013) judged the root variable's default, and TLSv1_2016 set in terraform.tfvars passed make scan. make scan now passes --tf-vars terraform/environments/prod/terraform.tfvars, and the same edit fails it.

Every assertion added or changed here was shown to fail on the bad configuration it exists to catch, and to pass on the real one; the health check's new tests were shown to fail against the script from main. Verification below lists them.

Alternatives considered#

Leave the module suites as they are and rely on name matching. It already catches some terraform.tfvars edits, but only by accident: it cannot see main.tf, a renamed variable breaks it silently, and a variables block in a test file overrides it without warning.

Wire production's values into the module runs (variables { x = var.x }). That restates main.tf in the tests, so a change to main.tf would still pass. Planning the root tests the composition that is applied.

Assert on a real plan's JSON with a script. It sees everything, but needs credentials and state, so it cannot run on a pull request, and it would be a second test framework.

Pass -var-file=terraform.tfvars explicitly. It would make the loading visible in the command, but make test and CI would both need it, and a run without it would still test the defaults. Removing the defaults fails closed wherever the suite is run from.

Remove origin_public, or rename it. Removing it loses a row a reader wants; renaming it changes the output, so the website would show nothing for the row until the owner applied. A precise label and description over the same key give the same truth with no apply.

Fail the health check on a real DKIM key rather than warn. Making the check able to not pass was the fault; changing its severity is a separate decision, and the DKIM wildcard is defence in depth behind SPF and DMARC.

Consequences#

Positive:

  • make scan judges the TLS policy production sets, not a default.
  • A change to terraform.tfvars or main.tf that undoes TLS 1.3 only, turns

on logging, attaches a WAF, opens the origin, turns off DNSSEC or the mail lockdown fails tofu test on its pull request.

  • The website's posture table can no longer say something the configuration

contradicts. If the configuration changes, the table and a failing test change with it.

  • p=none; sp=reject fails both tofu test and the twice-daily health check.

Negative:

  • Deliberately changing one of these decisions now means changing an assertion

in the same pull request, and saying why. That is the intent, but it is friction. In a DNSSEC emergency the Terraform route fails the suite too; the emergency runbook says so, and that it does not hold up the apply.

  • The production suite plans the whole root, so tofu test takes about half a

minute instead of seconds, and needs a mock for every computed attribute some resource validates. A new resource can need a new mock.

  • The suite mocks the homepage probe with a healthy response, because a failing

check fails a tofu test run. The live probe is not tested here; the health check covers it (ADR-0022).

  • origin_public is conservative: with any Block Public Access setting off it

says "Yes", even if the bucket policy still admits only CloudFront.

Neutral:

  • The plan of the production root does not change: every published value is

the same, only where it comes from. The website's row label changes on the next site-deploy.

  • email_policy_records is a new output of the dns-records module, not of the

root, so it is not in state.

Verification#

At the main commit, then with this change, one bad configuration at a time, running the whole suite:

Bad configurationBeforeAfter
terraform.tfvars: TLSv1.2_2021fails (by name)fails, also edge_posture_is_as_decided
terraform.tfvars: access logs onfails (by name)fails, also edge_posture_is_as_decided
terraform.tfvars: DNSSEC offfails (an index error)fails, also dnssec_is_on_and_watched
main.tf: access logs hard-coded onpassesfails
main.tf: TLSv1.2_2021 hard-codedpassesfails
main.tf: email lockdown offpassesfails
main.tf: DNSSEC off for the zone modulepassesfails, on the root's dnssec_chain_of_trust_is_actionable check
module: IPv6 offfailsfails
module: web ACL attachedpassesfails
module: a Block Public Access setting offfailsfails
module: OAC signing no-overridepassesfails
module: ACLs re-enabledfailsfails
DMARC p=none; sp=rejectpassesfails
DMARC p=quarantine; sp=rejectpassesfails
DMARC with no p tagpassesfails
DMARC with no sp tagfailsfails
DMARC not opening with v=DMARC1passesfails
terraform.tfvars: TLSv1_2016, under make scanpassesfails (AWS-0013)

The root's check blocks are evaluated by the production suite too, and a failing check fails the run: that is what catches DNSSEC turned off in main.tf, before dnssec_is_on_and_watched is reached.

Two valid records were run as controls and pass after the change: the tags reordered, and whitespace around ; and =. The first version of the new DMARC regex failed the second control, because it did not allow whitespace around =, which RFC 7489 permits; it was corrected and both were run again.

make test-health has eleven new tests for the DMARC and DKIM checks. Against the script from main, six fail: p=none; sp=reject, p=quarantine, no p tag, the version tag not first, two records, and a real DKIM key passing as revoked.

Current status#

25 November 2026, at merge: merged in PR #33. tofu test and make scan change for the next pull request, and the health check for the next dns-health run from main, with nothing to apply.

25 November 2026, later: in force. Before the merge, CI passed on the pull request's head, including all 32 test runs and the scan with production's terraform.tfvars, and its plan of the production root showed no changes ("0 to add, 0 to change, 0 to destroy", only the homepage check read), as expected. After the merge, site-deploy published the posture table from state: every value is unchanged, and the origin row reads "Origin can be made public: no". A manual dns-health run from main against testz.dev (run 245) passed all 30 checks with no warnings, including "DMARC policy is p=reject" and "DKIM wildcard revokes all selectors" against the live records; it owned the incident, and the incident job ran.

Revisit when#

  • tofu test stops loading terraform.tfvars from the root, or lets a test

file read production's values another way.

  • OpenTofu lets an assertion read a child module's resources directly, so the

production suite no longer needs outputs to reach them.

  • A second environment is added: its own root and its own production suite, or

one suite parameterised over both.

  • DMARC's record syntax changes (DMARCbis), or the domain starts sending mail.

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