The PR-ops engine¶
The engine is consumed at a pinned release tag; a customer repository does not copy it. It carries five thin caller workflows, so the customer repo only ever holds its own Terraform plus the callers.
The caller workflows¶
Each customer repository has five caller files in .github/workflows/:
| File | Calls | Trigger |
|---|---|---|
tfpr-pr.yml |
the dispatch composite action at nrit-solutions/tfpr/.github/actions/dispatch@vX.Y.Z |
Pull requests opened or updated: dispatch the ops caller on the default branch with the PR number. A consumer-owned pre-commit job gates the dispatch. |
tfpr-unlock.yml |
the same dispatch composite action |
Pull request closed: releases the PR's cross-PR unit locks. Its own workflow so a merged PR's checks list shows one row that reads as lock release. |
tfpr-review.yml |
the same dispatch composite action |
Review submitted or dismissed: dispatches the review command, which refreshes the tfpr / approval row on the head commit. |
tfpr.yml |
the reusable ops workflow nrit-solutions/tfpr/.github/workflows/terraform-pr-ops.yml@vX.Y.Z |
tfpr plan, tfpr apply, tfpr unlock comments, plus the engine's own dispatched work. Resolves the PR, writes every check and completes the merge gate. |
drift.yml |
nrit-solutions/tfpr/.github/workflows/drift.yml@vX.Y.Z |
A daily schedule and manual dispatch. |
The current pin is on Versions and upgrades.
The template also ships runner-canary.yml and runner-egress-check.yml,
which watch the self-hosted runners and do not call the engine. See
Workflows and discovery config.
Each caller is well under a hundred lines. They set permissions and pass a
couple of inputs; the ops and drift callers also pass two named secrets.
Nothing else. Most engine releases
need nothing beyond the pin bump, but not all: a release can add a caller
file, a permission line, or a projects.yml key, and its release notes state
the exact edit. Read the notes before bumping, whatever the version number
says.
Copy them as they are, keeping the PR caller's workflow name tfpr and
its job id pre-commit: GitHub renders that row as tfpr / pre-commit, the
only native row on the pull request. Every other row is an engine-created
check run named by the engine itself. The job runs the lint hooks and then,
as its last step, the dispatch action; a dispatch job of its own would wait
for a second runner on every push. The lint steps are convention, not engine
contract: they run the hooks from the repository's own
.pre-commit-config.yaml, and a repo may extend, weaken, or remove them;
the engine-enforced gates do not depend on them.
tfpr-pr.yml¶
tfpr-pr.yml runs from the PR branch, which any
writer can edit, so it holds no secrets and writes no checks; the ops run on
the default branch does both. Its pre-commit job installs the tools in
mise.toml and runs the hooks on the files the PR changes. A failed lint stops
the dispatch, so no plan runs and the merge stays blocked because the required
merge gate is never created.
tfpr-unlock.yml¶
tfpr-unlock.yml handles the closed event.
Splitting it out keeps a merged PR's checks list free of a second pre-commit
row. The dispatch action only dispatches the ops
caller, so no PR-side caller passes a secret or holds checks: write.
tfpr-review.yml¶
tfpr-review.yml runs on
pull_request_review (submitted, dismissed). A review starts no plan, so
without it the approval row would keep the last run's verdict until the next
push or comment. Its refresh job dispatches the ops caller with
command: review. That run reads the review decision and rewrites the
approval row an earlier run published on the head; it plans nothing and
leaves the merge gate alone. The row updates about 20 seconds after the
review, most of it runner start-up.
tfpr.yml¶
tfpr.yml grants the ceiling of permissions the
reusable workflow's jobs use: contents: read, pull-requests: write,
checks: write, and id-token: write. Its before_sha and trigger_actor
inputs are set by the PR caller's dispatch action as hints for wording only;
the engine resolves everything it decides from the API. It passes
TFPR_CHECKS_APP_PRIVATE_KEY and INFRACOST_API_KEY by name, because GitHub
drops secrets: inherit when the caller is in another organization than the
reusable workflow.
drift.yml¶
drift.yml runs daily at 06:17 UTC and on manual dispatch.
It needs issues: write and id-token: write, plus pull-requests: read so
the lock sweep can read the holder PR's state. It passes the same two secrets
by name.
The pins must match¶
Each caller carries one pin: its uses: ref. Five pins across five files, all
at the same version. The uses: ref is the whole pin: the workflow knows the
release it was called at, and each job installs the engine runtime of that
release. There is no separate input to keep in step.
Pin an exact release tag. The engine refuses a branch pin, except a
preview/* branch used to smoke an unreleased engine.
Software bill of materials¶
From v12.3.0, every engine release on the public nrit-solutions/tfpr
repository carries a signed SPDX SBOM for the tfpr binaries:
tfpr.spdx.json and its cosign bundle tfpr.spdx.json.bundle. Both are
listed in SHA256SUMS. Jobs do not download them. Verify one release:
TAG=vX.Y.Z
gh release download "$TAG" -R nrit-solutions/tfpr -p 'tfpr.spdx.json*'
cosign verify-blob tfpr.spdx.json --bundle tfpr.spdx.json.bundle \
--certificate-identity https://github.com/nrit-solutions/nrit-tfpr/.github/workflows/release-please.yml@refs/heads/main \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
It prints Verified OK. The identity is the engine's release workflow, so
the signature proves the SBOM came from the release build and not from the
transport. The runner image has its own SBOM; see
Verify a runner image release.
Where the engine scripts run from¶
Each job installs the engine runtime from the release that its uses: ref
names, on the public nrit-solutions/tfpr repository: the tfpr binary,
the gate scripts and the setup-tools action. Every file is checked against
the SHA256SUMS committed in that repository at the pinned tag (the release
is immutable and carries a copy for humans), and no token is needed. The
runtime lands under the runner's temp directory, outside
the checkout, exposed to hooks as $TFPR_ENGINE_DIR; only the setup-tools
action is copied into .tfpr-engine in the workspace, and a pull request
that commits anything under .tfpr-engine/ or gate/ is refused. Your
projects.yml calls the gate scripts from there:
steps:
post_plan:
- name: Policy check (conftest)
run: bash "$TFPR_ENGINE_DIR/scripts/conftest-gate.sh"
- name: Security scan (avmsec)
run: bash "$TFPR_ENGINE_DIR/scripts/avm-policy-gate.sh" avmsec
on_failure: warn
- name: Reliability check (APRL)
run: bash "$TFPR_ENGINE_DIR/scripts/avm-policy-gate.sh" aprl
on_failure: warn
- name: Security scan (checkov)
run: bash "$TFPR_ENGINE_DIR/scripts/checkov-gate.sh"
on_failure: warn
- name: Cost estimate (infracost)
run: bash "$TFPR_ENGINE_DIR/scripts/infracost-gate.sh"
$TFPR_ENGINE_DIR defaults to the workspace, so a vendored copy still resolves the
same paths. See Vendored mode below.
Upgrading¶
Callers pin an exact version. Nothing arrives automatically, so an upgrade is always a commit you can see and revert.
Bump the five pins in the five caller files to the same new tag, and read the
release notes first. When a release changes the ops caller's
workflow_dispatch inputs, the bump takes two pull requests, as v8 and v11
did; see Upgrading to v8 and
Upgrading to v11. For the caller
edits and license variables of v9, see
Upgrading to v9.
There is no moving major tag such as v1. The file always names the exact
engine a repository runs, and behavior never changes without a commit.
See Versions and upgrades for the full pinning contract, including the module and policy-library pins that live in the repository itself.
The security model¶
The reusable workflow splits jobs by trust so PR-branch code can never run with
write credentials: trusted jobs run the pinned engine runtime, and only the Azure-facing jobs run under the plan and apply
environments with an OIDC identity. The Security model page
covers the split, the identities, and the gates in full.
The callers reference the public entrypoint repository nrit-solutions/tfpr,
which holds the released workflows, the dispatch action and the runtime release
assets. No engine credential is needed. tfpr apply needs a license and an
entitlement in the TFPR_LICENSE and TFPR_ENTITLEMENT variables; see
License.
Enabling the engine on a repo¶
The bootstrap generates the customer repository from nrit-alz-customer-template,
which already ships the five callers and a projects.yml. To wire up a repo:
- Confirm
tfpr-pr.yml,tfpr-unlock.yml,tfpr-review.yml,tfpr.ymlanddrift.ymlpin the engine version you want, with the sameuses:ref in all five. - Confirm the repository variables
TFPR_LICENSEandTFPR_ENTITLEMENTare set (the bootstrap writes both fromtfpr_licenseandtfpr_entitlement;scripts/onboard.sh -f <path to the customer tfvars>fetches the entitlement;gh variable setis the fallback), and thatAZURE_TENANT_IDis the tenant the entitlement is bound to. Without them plan works andtfpr applyis refused. See License. - Create and install the org's checks App (see the checks App).
- Confirm
tfpr / merge-gateis a required check on the main branch. The bootstrap's ruleset requires it by default (required_status_checks), unless the tfvars set that variable to[]orrequire_approved_pr = false.
Branch protection and the merge gate¶
The engine writes a check run called tfpr / merge-gate, opened in
progress when a run takes the PR ("Planning 2 units", "Applying 1 unit"). Every
red verdict names the cause, then the next action. It concludes green only
when the PR has no Terraform changes, is a no-op, or has been fully applied.
Make it a required check on the main branch so unapplied changes cannot
merge. It is an API-written check run, so its name is the same in every
consumption mode.
tfpr apply also respects the repo's required reviews. That is configured entirely in
branch protection or the ruleset the bootstrap provisions; the engine reads
GitHub's review decision and blocks apply until it is met.
Every run that selects a unit also publishes a second check run, tfpr / approval,
carrying that review decision so the requirement is visible from the first plan.
A submitted or dismissed review refreshes it through the review caller.
tfpr / approval is informational
Do not make it a required check. It reports failure on every PR until
someone approves, and the branch rule already enforces the approval, so
requiring it adds no protection and can wedge merges. merge-gate is the only
engine check to make required. See
Command reference.
Tool versions¶
Pin Terraform and Terragrunt in mise.toml (or .tool-versions for asdf). The
setup-tools action detects the version manager and installs those versions, so a
version bump is a one-line change in the repo with no workflow edit.
Vendored mode, the escape hatch¶
A repo that cannot use the shared workflow can vendor the engine instead:
copy the engine source repository nrit-tfpr at a tag (it is private,
so this needs read access NRIT grants per agreement), including .github/,
scripts/, go.mod, go.sum, cmd/, and internal/, and run the workflows
directly with no uses:. The workflow then builds the
tfpr binary from the vendored Go source instead of installing a runtime
release, so the Go module files and source are not optional.
$TFPR_ENGINE_DIR defaults to $GITHUB_WORKSPACE, so the hook paths still
resolve. Vendored mode stays supported, but the repo then owns engine updates
by re-copying at a new tag.
A vendored engine runs the pull request's copy of itself
The jobs check the pull request head into the workspace, so the gate
scripts and the tfpr binary built from the vendored source are the pull
request's own copy. An author can edit the engine code to approve their
own apply. A vendored repository must require review of .github/,
scripts/, cmd/, and internal/ through CODEOWNERS and protect the
approvers team.
Prefer the reusable caller. Vendor only when a repository cannot call the shared workflow.