reusable-terraform-pr
Reusable GitHub Actions workflow for running Terraform plan on pull requests.
Usage
Basic usage
name: "Terraform PR"
on:
pull_request:
issue_comment:
types: [edited]
jobs:
plan:
uses: oslokommune/reusable-terraform-pr/.github/workflows/reusable-terraform-pr.yml@v2
secrets:
ssh-private-key: ${{ secrets.GOLDEN_PATH_IAC_PRIVATE_DEPLOY_KEY }}
Multiple SSH private keys
secrets:
ssh-private-key: |
${{ secrets.GOLDEN_PATH_IAC_PRIVATE_DEPLOY_KEY }}
${{ secrets.SOME_OTHER_DEPLOY_KEY }}
Inputs
| Name | Type | Default | Description |
|---|
config-file | string | .gp.cicd.json | Path to CI/CD configuration file |
selected-stacks | string | "" | Comma/newline-delimited list of stack patterns to plan (e.g., stacks/dev/{dns,iam}, stacks/dev/app-*). By default, only stacks with changed files are planned. On schedule and workflow_dispatch events the default is every stack in the repository (**). |
ignored-stacks | string | "" | Comma/newline-delimited list of stack patterns to always ignore. |
pr-automerge | boolean | false | Whether to evaluate Renovate PRs for automerge eligibility based on upgrade type and Terraform plan results. |
pr-automerge-rules | string | [] | JSON array of rules with pattern matching and per-update-type policies. Only used when pr-automerge is enabled. See automerge for details. |
max-parallel | number | 40 | Maximum number of plan jobs that run at the same time. Keeps new PRs with many stacks below GitHub's limit of about 80 new PR comments per minute. |
Outputs
| Name | Type | Description |
|---|
success | boolean | Whether all Terraform plans succeeded |
has-changes | boolean | Whether any stack had changes |
stack-results | string (JSON object) | Maps each planned stack to success, hasChanges and changeSeverity. hasChanges is null when the plan failed. See stack results. |
Stack results
stack-results is keyed by stack path. Each value has the same three fields:
{
"stacks/dev/app": { "success": true, "hasChanges": true, "changeSeverity": "additive" },
"stacks/prod/app": { "success": true, "hasChanges": false, "changeSeverity": "no-changes" },
"stacks/dev/slackbot": { "success": false, "hasChanges": null, "changeSeverity": null }
}
success: whether terraform plan succeeded for the stack.
hasChanges: Terraform's own verdict on whether the plan is non-empty, from its exit code. null when the plan failed, since drift is then unknown.
changeSeverity: the most severe kind of change the plan contains: no-changes < additive < non-destructive < any-changes. null when the stack was not classified (e.g. the plan or the classification failed); automerge then assumes the worst and treats it as any-changes. See With automerge for what each severity covers.
hasChanges and changeSeverity are derived independently: an import- or move-only plan is non-empty (hasChanges: true) yet safe (changeSeverity: "no-changes").
The keys are the planned stacks, so keys gives the full list.
Select stacks with jq, for example to_entries[] | select(.value.hasChanges) | .key for stacks with changes, or select(.value.success | not) for failed plans.
With manual trigger