Plan and apply¶
The pull request flow from open to merged: which units plan, how unit locks keep two pull requests apart, what the plan and apply comments show, and how apply walks the units in dependency order. The checks that can refuse a step are on Apply and merge controls.
The lifecycle¶
- Open a pull request touching one or more units. The engine plans every impacted unit automatically, one job per unit, in parallel. Only apply is dependency-ordered; a plan reads no other unit's output, so nothing has to wait.
- Read the plan comment. Each unit posts a fresh comment led by a headline with the result and the change counts, then one collapsed row per step in run order (the plan output, then each gate), and the apply instructions last.
- Get the required reviews.
tfpr applyrespects the repo's branch protection. - Apply. Comment
tfpr applyto apply everything in the PR, ortfpr apply -p <label>for one unit. Units apply in dependency order; units with no dependency between them apply side by side, two at once by default. - Merge. Once applied, the
tfpr / merge-gatecheck turns green and the PR can merge.
Commands¶
| Comment | Effect |
|---|---|
tfpr plan |
Re-plan all impacted units. |
tfpr plan -p <label> |
Plan one unit and its dependents. <label> is the unit path, its name, or its directory. |
tfpr apply |
Apply all impacted units, in dependency order. |
tfpr apply -p <label> |
Apply exactly one unit, no dependents. |
tfpr apply --force |
Apply even when a unit's plan changed since review, and run every unit instead of skipping no-ops. |
tfpr unlock |
Force-release the unit locks this PR holds. |
tfpr help |
List the commands as a reply on the pull request. |
Opening, updating, or reopening a PR runs tfpr plan automatically. A plan with
changes includes an instructions block telling you exactly which tfpr apply to run.
The impacted set¶
"Impacted" is wider than "has a plan diff", and wider than "the files you edited". A unit is impacted when any of three things is true:
- its own directory changed,
- one of the files it reads changed, or
- it is downstream of an impacted unit through a
dependenciesblock.
The read-files rule is the surprising one. Terragrunt reports every file a unit
pulls in, which includes root.hcl, customer.hcl, tenant.hcl, and the subscription.hcl,
env.hcl and region.hcl above it. A one-line change to live/root.hcl therefore impacts
every unit in the tree, because every unit reads it. Expect the full fan-out, and
expect most of those plans to come back as no-ops.
That is the intent. A shared contract change is planned everywhere it lands, not only where someone remembered to look.
Each impacted unit gets its own plan row on the pull request, with its own change counts. This PR touches two units:


Cross-PR unit locks¶
The first pull request to plan a unit owns it until that pull request merges or
closes. A second PR touching the same unit does not plan it: the unit reports a
locked result instead, with a comment naming the owning PR, a failing per-unit
check, and a failing merge gate that names the owning PR
(Unit locked by PR #n: apply or tfpr unlock it there, then comment tfpr plan). This stops
a stale plan in one PR from silently reverting what another PR applied.


Locks release five ways:
- Merging or closing the owning PR. This is the normal path; the unlock
caller (
tfpr-unlock.yml, triggered onpull_request: closed) is what makes it fire. - Commenting
tfpr unlockon the owning PR force-releases its locks, for when a PR is parked but should not block others. The engine confirms with a comment. - Automatically, when the owning PR turns out to be closed. A lock whose holder is already closed or merged (its release event was missed, for example when the head branch was deleted in the same instant as the close) is reclaimed by the next plan that wants the unit, so a stale lock cannot hold a unit hostage.
- On the drift schedule. The nightly drift run sweeps the lock table and releases every lock whose holder PR is closed or merged, so a leak heals without waiting for the unit to be contended. There is no age limit: an open PR's lock stays held however old it is.
- By manual dispatch. The ops workflow's
workflow_dispatchacceptscommand: unlockwith a PR number, for releasing a closed PR's locks by hand when the close event produced no run at all.
Re-running the blocked PR's plan after the lock is gone acquires it.
Ownership lives in an Azure Storage Table (tfprlocks) on the state storage
account, one row per unit; the bootstrap grants the identities access. Locking
skips itself on drift sweeps and manual dispatches, which never own units. A
repository can point locks at a different account with the
TFPR_LOCK_STORAGE_ACCOUNT variable, or turn the feature off with
TFPR_DISABLE_LOCKS set to true. See
Secrets and variables.
The plan comment¶
Each run posts a new comment, so the PR keeps a chronological history of runs. A comment reads top to bottom in the order the run happened:
- A headline with the result, the unit and the change counts, for example
✅ Plan (example): 0 to add, 1 to change, 0 to destroy. A plan that imports leads with the import count:1 to import, 0 to add, 1 to change, 0 to destroy. A plan that moves addresses carries the move count, which Terraform's own counts line leaves out:1 to move, 0 to add, 0 to change, 0 to destroy. A failed run reads❌ Plan (example) failed: <first error> (and 2 more errors): the first error's summary on one line, then the count of the others. Apply runs get the same headline,✅ Apply (example): 0 added, 1 changed, 0 destroyed. - A line under the headline with the unit path, the time in UTC and a link to the run log, at body size.
- An Error section, only when the run failed: up to three error diagnostics, each with its file and line, without the init log, the warnings, terraform's progress lines or terragrunt's repeat of them. Further errors are counted ("6 more errors in the Plan output") and stay in the collapsed output.
- One collapsed row per step, in run order. The
pre_initandpost_inithooks, then the plan output as a coloured diff, then thepost_planhooks. Each hook row is titled with itsnamefromprojects.ymland a one-line verdict, for exampleSecurity scan (checkov) · 5 failed, 11 passed. The gate rows are compact lists: checkov's failed checks grouped by resource, conftest's denies and warnings, infracost's monthly cost per priced resource. A row opens by itself when its hook failed or warned (on_failure: warn), and then also shows the hook's command and exit code. The output row of a failed run stays collapsed under the Error section; it opens by itself only when no diagnostic could be found. Its full console output stays in the run log. An open row's title shows the status in colour before the verdict,warningin yellow orfailedin red, for exampleSecurity scan (checkov) · warning · 5 failed, 11 passed, so a warning never reads like a blocking failure. An opened row's body starts one line below its title. - Instructions last, when the plan has changes: "To apply these
changes" with
tfpr apply -p <unit>, "To apply all changes in this PR" withtfpr apply, and "To unlock this PR's units without applying" withtfpr unlock.
A plan comment with its output opened. The gate rows stay collapsed because every gate passed:


A failed run leads with the first error in the headline and the Error section above the collapsed output:


There is no change table in the comment; the list of resource changes lives in the per-unit check (see below). A plan too long for one comment continues in follow-up comments, split at resource headers, up to five comments; past that the rest is in the run log. The pre-plan rows stay in the first comment, the post-plan rows and the instructions in the last. Failed and warned hook rows get their share of the space before clean ones.
An imported resource counts as a change (import, or
import,update when the same plan also changes it) and a removed block as
forget, so an import-only plan counts as a change and tfpr apply lands it.
A moved address counts the same way (move, or move,update), so a module
bump that only moves resources is applied, not skipped.
The per-unit checks on the PR are titled with the change counts (for example
Plan: 2 to add, 1 to change, 0 to destroy), so the checks tab is scannable
without opening runs. When the plan imports something the title leads with
the import count, Plan: 1 to import, 0 to add, 0 to change, 0 to destroy,
and the apply title reads Resources: 1 imported, 0 added, 0 changed, 0
destroyed, the same way Terraform prints them. A move is counted the same
way, Plan: 1 to move, ... and Resources: 1 moved, .... When a
new report posts, the unit's previous reports
of the same command are marked as Outdated and get a banner linking to the
report that replaced them; the history stays in the timeline, collapsed,
and only the latest report per command reads at full size, so an apply
report never buries the plan report that was reviewed. Superseded per-unit
check rows of the same command flip to a neutral "Outdated" the same way,
so a failed or refused run's red row does not outlive its successful
retry. Set the TFPR_MINIMIZE_OUTDATED repository variable to false to
opt out of the comment sweep.
A push while the PR's apply is still running does not plan on top of it.
The plan and apply jobs of one pull request share a concurrency group, so
the new commit's plan queues until the apply finishes and then plans the new
head. Because GitHub shows the checks of the newest commit only, the running
apply's rows drop out of view the moment you push; the new commit's plan
checks therefore open with the title Waiting for apply #N on <sha>, with a
link to the apply job in their summary, and switch to In progress when
their plan starts. The same applies to a tfpr plan or tfpr apply typed while an
earlier run is still on the runner.
While a unit runs, its check row's title shows where it is, and the merge box
shows it next to the row: Initializing, Planning: 34 resources refreshed,
Running checkov, Applying: 3 changes done. A phase change updates the row
at once, a counter at most every 10 seconds; every update is an API write, and
GitHub caps those per repository, so the engine keeps it to a handful per
unit. Set the TFPR_CHECK_LIVE_LOG repository variable to true to also see
the latest 30 lines of output in the check's text, refreshed about every 30
seconds. The run summary replaces it when the unit completes. The PR comment
still posts once, at the end.
The apply comment¶
An apply posts a comment of the same shape, and its Terraform output is filtered down to the real actions. What is hidden is a fixed list: the refresh lines, the ten-second "Still creating..." updates, Terragrunt's log prefixes, its retry chatter, and runs of identical blocks. Every other line passes through, so an error cannot be filtered away, and the verdict comes from the exit code rather than from anything in the text. A resource still running when the apply ended gets a line of its own at the end, so nothing is left mid-create with no outcome.
Plan output is not filtered.
The apply comment carries no gate rows. Its layout is the
plan's: the Apply (<unit>) headline, the line under it, then the pre_apply hook
rows, the apply output and the post_apply hook rows, in that order. The
apply re-takes a plan the reviewed-plan guard has just matched to the one the
plan run gated, so the gates are not run again; a one-line note under the
headline says so: "Plan checks not re-run: this is the same plan that was
reviewed at <commit>". A repository that wants a gate at apply time
lists it under the apply: stage of steps: (see the
hook and step model).


Comment reactions¶
The engine adds a single 👀 reaction to your tfpr plan or tfpr apply comment, so you
can see the command was picked up without opening the run. That is the only
reaction an accepted command gets. The outcome is carried by the report comment,
the per-unit check, and the merge gate, so a running and a finished reaction would
only add noise to the same answer.
A refused or unauthorized command still gets 😕, because there nothing else reports the outcome: no run starts, so there is no report comment and no check.
The running and final states appear as a check run (a spinner, then a green
check or red cross) in the PR's Checks section, one per unit, named
tfpr / <command> (<label>) #<run number> under the org's checks App.
The run number keeps two runs on the same commit apart; when a newer run of
the same unit and command completes, the older row is swept to neutral with
the title Outdated: superseded by #N, so exactly one row per unit and
command stands. Only tfpr / merge-gate is meant to be a required
check: the per-unit names are not stable across runs, and
tfpr / approval is informational and must never be required.
An engine-created check has no inline log, so its "View more details" link
matters: it opens the job that ran the unit (the plan
matrix job, or the single ordered apply job), one click to the live log.
When the engine cannot resolve the job, the link falls back to the run
overview. That log holds the full terraform or terragrunt
output, one foldable group per command (for example terragrunt plan
<label>), so a plan the PR comment truncated can be read in full there.
The check itself also carries a run summary, shown when you
open the row: what triggered the run and who (a push, the comment command,
or a manual dispatch), a table of each resource change as action and
address, one line per gate (checkov and conftest pass and fail counts,
the infracost monthly total), and one line per hook with its
name, slot, status and verdict, so a warned scan shows as ⚠️. It never holds plan output or attribute
values; those stay in the PR comment and the job log. Two hidden markers
at the top carry the same facts as data, so tooling can read a run from
the check runs alone without reading comments. A very large change list is
cut with a +N more row to fit GitHub's size limit. When a row is swept to
Outdated, it keeps its summary.
Dependency-ordered apply¶
Apply is a single job, not a parallel matrix, so Terragrunt units apply after the units they depend on. If a dependency fails, its dependents are skipped rather than applied against stale state, and the skipped units are reported.
The impacted set is often larger than the set of units with a real diff: a
change to a shared file (like root.hcl) impacts every unit that reads it.
A unit whose reviewed plan shows no changes is skipped
outright during apply: no init, no plan, no apply; its check completes green
with "No changes; apply skipped" and no report comment is posted. The one
exception is a unit downstream of a unit that just applied changes: its empty
plan was taken against pre-apply outputs, so it re-plans for real and the
reviewed-plan guard judges the result. tfpr apply --force disables the skip.