Re-plan a pull request from a comment
Optional: hand this page to your coding agentThe steps work by hand too.Show the whole prompt
Read https://intentius.io/terragucci/guides/re-plan-from-a-comment/.
Check that the default branch's pipeline has the comment trigger (on GitLab, the `comments` job and a pipeline schedule with TERRAGUCCI_SCHEDULE set to comments); if it does not, run `npx terragucci init` and open a pull request with the result.
You may comment `/terragucci plan` on a pull request and report what the note says.
Never comment `/terragucci apply`, `/terragucci lock` or `/terragucci unlock`.
Never apply, approve (a pull request review or `terragucci approve`), override a policy denial (`terragucci override`), use `--mode apply`, or merge; never touch `.chant/allowed_signers` or `chant/lifecycle`.Result
Section titled “Result”/terragucci plan on a pull request plans it again and updates its plan note and terragucci/plan status. /terragucci plan envs/dev/orders plans that root alone.
Prerequisites
Section titled “Prerequisites”| You need | Why |
|---|---|
| The pipeline with the comment trigger | comment workflows run from the default branch; to add it, run npx terragucci init again and merge the result |
| Write access to the repo, for whoever comments (on GitLab, the Developer role or above) | anyone else gets no answer and no plan |
Each new pull request comment starts the replan job.
GitLab starts no pipeline for a merge request note. A pipeline schedule polls for notes instead and answers each on its next run.
| Step | What to do |
|---|---|
| Turn it on | add comments: "*/5 * * * *" to terragucci.yml, run npx terragucci init, and merge the result; the pipeline gets a comments job |
| Add the schedule | under CI/CD, Schedules: the same cron, the default branch, and the variable TERRAGUCCI_SCHEDULE set to comments |
| The token | GITLAB_TOKEN (or the token_env variable): a project access token with the api scope and the Developer role, in a masked variable |
The comments job runs from the default branch and holds no cloud credentials. It reads notes and calls GitLab’s API: /terragucci plan starts a new merge request pipeline, whose plan job updates the plan note. Each reply carries a marker, so a note is answered once.
As on GitHub.
-
Comment on the pull request with this line alone:
/terragucci planThe optional word after
planis a root path from the repository root. -
Read the note. The
replanjob plans the head with the read-only role and no forge token, and thereplan-notejob updates the same note and status.The re-plan edits the note in place.
When the pipeline the
commentsjob started has planned, it edits the note.The re-plan edits the note in place, above the comment.
A named root the change does not reach gets a “not affected” reply and no update; a name that is not a root is refused with the list of roots.
Re-plans by dispatch
Section titled “Re-plans by dispatch”A chat front end or a script can re-plan without a comment. On GitHub and Forgejo the workflow takes a workflow_dispatch:
| Input | Value |
|---|---|
pr |
the pull request’s number. Drift runs by hand from its own workflow, terragucci-drift.yml (Turn on drift checks) |
root |
optional: one root path, read by the comment grammar |
The re-plan runs the same checks as /terragucci plan [root] and updates the same note and status.
gh workflow run terragucci.yml -f pr=42 -f root=envs/dev/ordersThe decision step asks the API for the dispatcher’s permission and plans nothing without write access.
GitLab has no dispatch with inputs. Run a new merge request pipeline instead (Run pipeline on its Pipelines tab), or call the API:
curl -X POST -H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
"$CI_API_V4_URL/projects/<id>/merge_requests/<iid>/pipelines"It needs the Developer role or above, and plans the whole merge request.
curl -X POST -H "Authorization: token $FORGEJO_TOKEN" -H 'content-type: application/json' \
-d '{"ref":"main","inputs":{"pr":"42"}}' \
"https://forgejo.example.com/api/v1/repos/acme/infra/actions/workflows/terragucci.yml/dispatches"Forgejo answers 403 to a dispatcher without write access and starts no run. Its dispatch event carries no permission to read, so that refusal is the check.
Comment forms
Section titled “Comment forms”The text is untrusted and never reaches a script. terragucci comment reads it from the event file, or on GitLab from the API. Only one line in one of these forms is accepted; anything else is refused with the reason.
| Comment | Runs | Where | GitLab, with comments: set |
|---|---|---|---|
/terragucci plan |
a re-plan | every GitHub and Forgejo pipeline | a new merge request pipeline |
/terragucci plan <root> |
a re-plan of that root, which must be exactly a root the pipeline knows | every GitHub and Forgejo pipeline | the root is checked, and the whole merge request is planned |
/terragucci apply |
the approved waves | merged pull requests; open ones with apply.when: pull-request |
merged merge requests: a retry of the merge commit’s first apply job that did not succeed; with apply.when: pull-request, open ones: chant’s decision, then the waves’ pipeline on the default branch |
/terragucci apply wave-<n> |
the approved waves up to wave n | as above | an open merge request with apply.when: pull-request; otherwise refused, since GitLab runs the waves after a retried job by itself |
/terragucci lock |
locks on the roots (in a Terragrunt repo, the units) this pull request reaches, with no apply | locks: plan under apply.when: merge; with apply.when: pull-request, /terragucci apply takes the locks |
answered as unsupported |
/terragucci unlock |
a release of this pull request’s locks | as lock |
as lock |
atlantis plan [-d <dir>], atlantis apply |
the same as /terragucci plan [<root>] and /terragucci apply, with the same checks |
atlantis_comments: true |
the same, with atlantis_comments: true |
/terragucci agent <ask> |
a coding agent’s change | agent.comment set; see Have an agent change a pull request |
with agent.comment set, starts the agent’s pipeline on the default branch; otherwise answered that it is off |
No comment approves, and a re-plan cannot change what an approval binds. When a comment runs nothing lists every check each command must pass. A refusal is a reply that starts with terragucci:.
| Case | Job |
|---|---|
| a comment that asks for nothing | ends cleanly |
| a forge 403 or failure, or an unreadable event file | fails, with the cause in the log |
Limit comments to a team
Section titled “Limit comments to a team”A comment command needs write access to the repository. comment_allow in terragucci.yml narrows a command to a list of logins and teams, so that moving from a setup that maps teams to commands keeps the same people:
comment_allow:
unlock: ["team:acme/platform", alice]
skip-soak: ["team:acme/release"]A key is a command (plan, apply, lock, unlock, agent, action or skip-soak) or default for every command the map does not name. An entry is a login, or team: and the team’s path: team:<org>/<team> on GitHub and Forgejo, team:<group path> on GitLab, where it means the group’s members, inherited ones included. A command with no list keeps write access alone. An empty list is refused, since it would let nobody run the command.
The list is read from terragucci.yml in the job’s checkout, which is the default branch, so a pull request cannot add its author. Someone with write access who is on no list for the command gets a reply that names the list, and nothing runs.
Where it is read depends on who answers the comment.
| Forge | Limited by comment_allow |
Write access alone |
|---|---|---|
| GitLab | plan, apply, lock, unlock, agent and skip-soak, in the comments job |
|
| GitHub and Forgejo | action, skip-soak, and lock and unlock under locks: plan with apply.when: merge |
|
| GitHub and Forgejo, chant’s jobs | plan, apply and agent, and lock and unlock under apply.when: pull-request, with a terragucci built on chant 0.124.98 or newer |
the same commands, with a terragucci built on an older chant |
chant’s jobs read the list in the workflow the generator wrote, which is the default branch’s copy: the re-plan checks plan before it plans, the apply-comment job checks apply (and lock and unlock before merge), and the agent checks agent. A default covers them too. The re-plan and the apply-comment job reply to someone the list leaves out; the agent’s push job does. With a terragucci built on an older chant, those commands check write access alone, so config check refuses a list for them and a default, naming the chant release, and a list that would limit nothing is never written. A dispatch of the re-plan asks no list, as it asks no permission.
Team membership is read from the forge’s API with a token, and the job’s own token cannot read it on GitHub. Set a token that can and name it TG_TEAM_TOKEN; a job falls back to TG_TOKEN when it is unset.
| Forge | What the token needs |
|---|---|
| GitHub | a secret TG_TEAM_TOKEN holding a token that can read the organization’s members: a fine-grained token or app with the organization permission Members: read, or a classic token with read:org; the generated workflows pass it to the jobs that check a team, chant’s among them |
| Forgejo | a secret TG_TEAM_TOKEN holding a token with read:organization |
| GitLab | a CI/CD variable TG_TEAM_TOKEN, or the comments job’s TG_TOKEN, belonging to a user who can see the group’s members (read_api) |
When the forge cannot answer (the token lacks the permission, or the team does not exist or is not visible to it) nothing runs, the job fails, and the reply says that membership could not be read. A pending invitation to a GitHub team is not membership.
Apply a merged pull request
Section titled “Apply a merged pull request”On a merged pull request, /terragucci apply re-runs the waves’ jobs of the merge commit’s run that did not succeed, for the waves approved as Approve a waiting wave shows.
| Part | What happens |
|---|---|
| Workflow | apply-comment, chant’s comment job, runs the default branch’s workflow; it holds no cloud credential and runs none of the change’s code |
| Checks | apply-comment checks the comment before it re-runs anything, against the merged-PR column |
| Credentials | the re-run wave jobs assume oidc.apply_role, as on a push |
| Another run’s resources | with choudoufu, a wave that changes a resource another run is applying is refused; the reply names that run, and you comment again once it is done |
| Waves | from wave 1 until one does not apply; wave-<n> stops after wave n |
| A waiting wave | waits as on a push |
| A refused wave | prints its diff (respond.wave-refused) |
| A failed wave | prints its triage (respond.apply-failed) |
| Terragrunt | the same job and refusals; each wave job runs terragucci run wave on its units from the merge commit |
| On GitLab | |
|---|---|
/terragucci apply |
retries the waiting wave’s job in the merge commit’s pipeline |
| The gate | the wave job decides it again, so a wave with no approval waits again; the waves after it follow, each behind its own gate |
| A merge commit a later apply superseded | refused, as on GitHub |
Apply an open pull request
Section titled “Apply an open pull request”With apply.when: pull-request, /terragucci apply on an open pull request applies its head before merge. Apply a pull request before it merges has the steps.
/terragucci apply takes the locks of the roots the change reaches when it decides the head, and /terragucci lock and /terragucci unlock do not run. Locks lists everything that takes and releases one.
| Comment | Does | Refused when |
|---|---|---|
/terragucci apply |
locks the roots the pull request reaches, then applies its head | another open pull request holds one of those roots; the reply names it |
/terragucci plan, under locks: plan |
takes the locks again once a holder is gone |
- Approve a waiting wave is the one place an approval is given.
- Stages lists what
tf-planreads and writes.
terragucciHelp setting it up: Intentius
These docs count page views and clicks with PostHog. They set no cookies, store nothing in your browser, and send nothing when your browser asks not to be tracked.