Runbook: drift between main and production#

What the weekly drift-detection workflow reports, what to do when it opens an issue, and how to turn it on and prove it can fail. The decision behind it is ADR-0021.

Status, 25 November 2026: in force. Steps 1 to 4 under Turning it on were done the same day, and each behaved as described: drift before the apply, clean after it, and a simulated failure reported as an error. Step 5, the first scheduled run, is still to come.

What it does#

Every Monday at 04:41 UTC (in practice some hours later: GitHub starts scheduled runs late), the workflow plans main against production with the read-only plan role. It keeps one open issue labelled drift while the answer is anything but clean, adds a comment to it on each run, and closes it on the first clean run.

VerdictMeansIssueRun
cleanNothing would change except the homepage check's read, which every plan containsClosed, if openGreen
driftA resource or a root output would changeOpened or commented on, titled Drift: production does not match mainRed
errorDrift is unknown: the plan failed, the job did not finish, or the plan held something the verdict could not explainOpened or commented on, titled Drift detection failed to runRed

A run from any branch but main is refused before it plans, and touches no issue.

The issue says drift#

The issue lists each change by address. There are two causes, and they need opposite fixes.

  1. A merged change was never applied. The list matches what recent pull

requests changed, and their plan comments showed the same changes. Fix: Actions → terraform-apply → Run workflow, from main, and read its plan before it applies. The next drift run closes the issue; to close it at once, run drift-detection by hand afterwards.

  1. Someone changed production outside OpenTofu. The list includes changes

no pull request made. Do not apply yet: applying undoes the change, and it may have been an emergency fix (the DNSSEC emergency runbook has one). Find out who changed it and why: CloudTrail → Event history, filtered by the resource name. Then either put the change into code through a pull request, or apply main to undo it.

Notes at the bottom of the report list changes made outside OpenTofu that the configuration does not manage, each with the names (never the values) of the attributes that changed. They are not drift and need no action, but an unexpected one is worth the same CloudTrail look.

The issue says drift detection failed to run#

Drift is unknown, not absent. Open the run linked in the issue and read the Plan and judge step.

Log saysCauseFix
Set the repository secret AWS_ACCOUNT_IDThe secret is missingRestore it (bootstrap runbook)
Not authorized to perform sts:AssumeRoleWithWebIdentityThe plan role no longer trusts mainCI role trust runbook
An OpenTofu errorThe plan itself failed, which a pull request plan would also showFix it on main like any failed plan
The plan format may have changed or no actionsOpenTofu's JSON plan changed shape after an upgradeUpdate scripts/drift-verdict.py and its tests
Simulated failureSomeone ran it with simulate_failureRun it again without

The issue stays open until a clean run.

Turning it on#

Item 5 of the roadmap is apply main, then add drift detection, and the first run before the apply is the best test there is: production is behind main, so drift detection must report drift. Do these in order, after the pull request is merged. Each step says how to confirm it and how to roll it back.

Nothing here changes what a role trusts, so bootstrap-account is not needed.

1. Prove it sees drift#

Do: Actions → drift-detection → Run workflow, from main, with simulate_failure unticked.

Confirm: the run is red, and an issue labelled drift, titled Drift: production does not match main, lists at least:

  • module.edge_api[0].aws_lambda_function.this: update (the COMMIT_SHA

environment variable goes, and the handler changes);

  • output.site_facts: update (its commit field goes).

If the run is red with Drift detection failed to run and the log shows Not authorized to perform sts:AssumeRoleWithWebIdentity, the plan role does not accept a token from main outside a pull request. That would be the first time this has been tried: pull request plans have used the role, and no run from main had. It is then a bootstrap-layer change, made through the CI role trust runbook. Stop here.

Roll back: nothing changed. Close the issue if you are stopping.

2. Apply main#

Do: Actions → terraform-apply → Run workflow, from main.

Confirm: the plan in the log is one in-place update to module.edge_api[0].aws_lambda_function.this and the site_facts output change, plus the homepage check's read. Then the apply is green, the summary shows no failing check, and the Deploy website job is green. That job builds the site with the run's commit and refuses to deploy otherwise. Then:

curl -s https://testz.dev/api/whoami | grep handler_source
git hash-object terraform/modules/edge-api/src/handler.py   # on main: must match
curl -s https://testz.dev/ | grep -o 'from commit <code>[0-9a-f]*'   # the commit applied

Roll back: revert the merge on main and run terraform-apply again. That restores COMMIT_SHA and the old handler.

3. Prove it sees no drift#

Do: run drift-detection again, from main.

Confirm: the run is green, its summary says verdict: clean with one ignored check-block read, and the issue from step 1 has a closing comment and is closed.

If it reports drift, something besides this change differs. Read the issue; it is real drift, and this section of the runbook applies.

4. Prove a failure is never clean#

Do: run drift-detection from main with simulate_failure ticked.

Confirm: the run is red, and an issue titled Drift detection failed to run is opened. Its report ends with Simulated failure. Then run it again unticked: green, and the issue closes.

Roll back: nothing changed.

5. Watch the first scheduled run#

Confirm: the Monday after, a run with the event schedule appears and is green. Expect it hours after 04:41 UTC.

6. Record it#

In a pull request: item 5 of the roadmap is done, with the date; the status lines here, in ADR-0021 and on the living documentation page change to in force.

Taking it out#

Delete .github/workflows/drift-detection.yml in a pull request, or disable it (Actions → drift-detection → ⋯ → Disable workflow). Close any open drift issue. Nothing in AWS changes.

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