Only auto-approve the Terraform apply on workflow_dispatch - #189
Merged
Conversation
|
Terraform plan in terraform No changes. Your infrastructure matches the configuration.✅ Plan applied in Apply Terraform changes on merge #44 |
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.
Closes #187.
On a push to
mainthe apply no longer approves its own plan.dflook/terraform-applyfinds the pull request the pushed commit came from, reads the plan comment posted on it, and re-plans — applying only if the new plan is logically the same, and failing withplan-changedif it has drifted. What reaches production is then the plan a reviewer actually saw.workflow_dispatchis new here and keepsauto_approve: true, because there is no pull request on that path and so no plan to match against. It exists as the recovery route: when a merge-triggered apply failsplan-changed, re-running it from the Actions tab replays the same push event and fails identically, so without a manual trigger there is no way back at all.That dispatch path is the unreviewed one, and what makes it safe is #182.
devops-security-tf-applyconditions itssubonrefs/heads/mainonly, so a dispatch from any other branch presents a differentsuband AWS refuses the AssumeRole outright. This change was deliberately blocked on that work — under the static keys it replaced, which carried no branch scoping, the same trigger would have been an unreviewed apply runnable from anywhere.terraform/aws-gha-oidc-providers.tfnow records that the narrowness of that condition is load-bearing, so nobody widens it torefs/heads/*without realising what it switches on.Verified before making the change:
role-to-assume: …/devops-security-tf-apply, confirmed onmain, which is action item 1 on the issue.pull-requests: writeandGITHUB_TOKENare both already present. Neither needed adding, but the action uses them to read the plan comment, so this change is what makes them load-bearing rather than incidental.pushis a documented trigger forauto_approve: falsein the pinned v1;workflow_dispatchis not, which is why that path keepstrue.Why there is a Terraform change in a workflow pull request. Both workflows filter on
paths: ['**/*.tf'], so a pull request touching only workflow files triggers neither, and this would sit unexercised until somebody else's Terraform change landed. The note above is itself a.tfchange, so the plan runs here and the apply runs on merge.Two new ways a merge can fail, worth saying out loud rather than discovering:
mainrequires a review but has no required status checks — and that now produces a failed apply instead of a silent auto-apply. Making the plan a required check is the natural follow-on and is not done here.mainhas no originating pull request and therefore no plan comment, so it will fail. Recovery isworkflow_dispatch.Do not read a green run as proof the gate works — check which branch it took. In the action's
apply.shthe condition isif [[ "$INPUT_AUTO_APPROVE" == "true" || $PLAN_EXIT -eq 0 ]], andPLAN_EXITof 0 is Terraform's "no changes" code, so a no-op plan is applied without ever comparing against the pull request comment. The log then readsauto_approve: falsefollowed byAutomatically approving plan, which looks like the change failed and has not. Expect exactly that here, since this pull request changes no infrastructure. The first pull request that changes real IAM configuration is the true first exercise of the comparison.