fix(terraform): make apply find the reviewed plan [NOJIRA] - #342
Merged
Merged
Conversation
The plan artifact was named with github.sha, which on a pull_request event is the ephemeral refs/pull/N/merge commit. Apply looks up the pushed commit and then the PR head, so it matched neither and every apply failed with "No reviewed plan". Name it with the PR head SHA instead. Also: - terraform-ok now gates on discover. Discovery hard-fails on a stack with no accounts[] entry, which leaves terraform skipped, not failed, so the required check went green on a failed discovery. - discover passes through any extra key on the matched accounts[] entry. A repo with one static key pair per AWS account (terraform-core has four) had no way to carry the secret name to the caller. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
tobias0106
requested review from
sudheer-monta
and removed request for
a team
September 10, 2026 10:13
prasad-manu
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #341. Three defects found while validating that workflow against the three Terraform repos — all of them block the first adopter.
1. Apply can never find the plan. Blocking.
terraform-stack.ymluploadstfplan-<slug>-${{ github.sha }}. On apull_requesteventgithub.shais the merge commit ofrefs/pull/N/merge— ephemeral, and equal to neither the commit that lands onmainnor the PR head. Apply looks up the pushed commit, then falls back to.head.shavia/commits/{sha}/pulls. It matches neither, so every apply fails withNo reviewed plan.A merge queue does not rescue it: all three repos enforce
required_linear_history, so the queue squashes or rebases and the landed SHA differs from themerge_groupSHA too. None of the three has a merge queue configured today anyway.Fix: name the artifact with
github.event.pull_request.head.sha || github.sha. The download step's existing head-SHA fallback then resolves it for squash, rebase and merge-commit alike.2.
terraform-okgoes green on a failed discoveryDiscovery deliberately hard-fails a stack with no
accounts[]entry. That leavesterraformskipped, not failed, and[[ result != 'failure' ]]passes onskipped— so the only required status check reports success while nothing was planned. It now gates ondiscovertoo, and treatscancelledas a failure.3. No way to pass per-account static keys
terraform-corehas four AWS accounts with a key pair each (TERRAFORM_CORE_{INTERNAL,MONTA,PRODUCTION,STAGING}_AWS_*) and no OIDC roles yet — it is the suggested first adopter. The discover jq built a fixed{dir, role, environment, region}object and dropped every other key, so the caller had nothing to select a secret with, and GitHub expressions have noupper()to derive one fromenvironment.Discovery now passes through any key on the matched
accounts[]entry exceptmatch:Defaults and first-match-wins are unchanged; an unmatched stack still fails discovery.
Not fixed here
The over-wide fan-out already called out in #341. Still blocking for
terraform-db-access, and worth landing beforemonta-app/terraformadopts: that repo's rootmain.tfdeclares its own S3 backend without abackend.tf, so any change to it fans out to all four stacks on apply.🤖 Generated with Claude Code