Skip to content

feat(terraform): dismiss approvals when the plan changes - #399

Merged
tobias0106 merged 1 commit into
mainfrom
terraform-dismiss-stale-approvals
Nov 10, 2026
Merged

tobias0106 merged 1 commit into
mainfrom
terraform-dismiss-stale-approvals

Conversation

@tobias0106

Copy link
Copy Markdown
Contributor

Adds an opt-in dismiss-stale-approvals input to terraform-stack.yml. With it on, an approval covers a plan rather than a commit. This came out of the discussion on monta-app/terraform#461 (Zipper): a PR approved on a harmless plan can pick up a mass replacement from a rebase, and then gets merged and applied without anyone looking.

How it works (pull requests only):

  • After the plan, terraform show -json → a sha256 over resource_changes, minus no-op and read. The hash covers address, actions, after (sensitive values masked as (sensitive)), after_unknown, replace_paths and importing. Resource order doesn't matter, and drift outside the PR (resource_drift) is left out.
  • The fingerprint is stored per head SHA in the stack's plan comment as <!-- terraform-plan-fingerprint:<sha>:<hash> -->, keeping the last 50.
  • Each reviewer's latest review that is APPROVED is checked against the fingerprint recorded for its commit. If it differs, or no plan was recorded for that commit, the approval is dismissed with a message naming the stack.

Behaviour:

  • A rebase that leaves the plan unchanged keeps the approval, so Zipper or the author can merge.
  • A rebase that changes the plan dismisses the approval, and someone has to review the new plan.
  • A secret-only change (a masked value) does not change the fingerprint.
  • When it's first turned on, approvals from before have no recorded fingerprint and are dismissed on the next plan. That happens once.

Not tested in CI yet. The jq fingerprint was tested locally on sample plans: ordering and masked secrets are ignored, and a changed value changes the hash. The JS passes a syntax check. The first real run will be monta-app/terraform with the input on.

Callers pin by SHA and the input defaults to false, so nothing changes for other repos.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tobias0106
tobias0106 marked this pull request as ready for review November 10, 2026 18:32
@tobias0106
tobias0106 requested a review from a team as a code owner November 10, 2026 18:32
@tobias0106
tobias0106 requested review from maoanran and removed request for a team November 10, 2026 18:32
@tobias0106
tobias0106 merged commit 2caf4ff into main Nov 10, 2026
1 check passed
@tobias0106
tobias0106 deleted the terraform-dismiss-stale-approvals branch November 10, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants