Skip to content

Roll out a new module version

llms.txtlists every page for an agent
Optional: hand this page to your coding agentThe steps work by hand too.
Show the whole prompt
Read https://intentius.io/terragucci/guides/roll-out-a-module-version/.
Run `npx terragucci rollout <module>` (the preview only), fix any pin it refuses
in a pull request, and print the `--mode apply` command for me to run.
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`.

Every root that pins the module moved to the new version through one pull request per wave.

You need Why
Roots that pin the module exactly by oci:// tag or digest, registry version or git tag a range cannot move (Stages lists the cases)
The new version published (Publish your modules) the rollout pins roots to it
The HCL parser beside terragucci: npm i -D @cdktn/hcl2json the rollout edits each root’s pin with it
A forge token that can open pull requests, in the variable token_env names the apply run and the rollout job open the rollout’s pull requests with it
Optional: waves.canary in terragucci.yml it picks the roots that move first
Optional: rollouts in terragucci.yml a scheduled job opens each next wave, so nobody runs step 5
  1. Preview the rollout.

    Terminal window
    npx terragucci rollout modules/network

    Name the module by path or by source without the pin, and leave out the version to get the newest published. The dry run changes nothing. When pins disagree, --from picks which moves.

    For a module that modules.registry publishes, modules/network also names the calls whose source is its registry address, such as modules.example.com/acme/network/generic, and their version moves. With no version named, the newest the registry lists counts too.

  2. Fix any pin it refuses. The preview lists each pin it cannot move, with a tip:

    The pin Tip
    a range such as ~> 1.4 rollout-floating-pin: pin one version
    set from a variable or a local rollout-literal-pin: write a literal, since a variable’s value is not in the diff
    absent from the source rollout-pin: add a ?ref=, ?tag= or version
    two versions of the module in one directory rollout-one-pin: pin every call at one version

    Do that in its own pull request, then run the preview again.

  3. Open the first wave.

    Terminal window
    npx terragucci rollout modules/network 1.4.0 --mode apply

    --mode apply writes to the forge and runs no terraform apply; roots apply after the merge. It opens one pull request for the canary wave, or the first in dependency order. Only that wave’s files change, and each pin keeps its shape.

  4. Review and merge it. The apply stage runs on the merge commit.

  5. Let the next wave open. With rollouts set, init writes a job that runs terragucci respond rollout --mode apply on that schedule:

    rollouts: "*/15 * * * *"
    token_env: ROLLOUT_TOKEN

    Each run opens the next wave of every rollout whose last wave merged and applied, so a wave opens within one interval. A rollout with a pull request still open, or one closed unmerged, is left alone.

    Forge Job Token Schedule
    GitHub its own workflow, terragucci-rollout.yml, which you can also start by hand, with the module and version inputs below the secret token_env names, else the job’s own; GitHub runs no workflow for a pull request the job’s own token opens, so name a secret holding a token that can push branches and open pull requests the rollouts cron
    Forgejo the same the secret token_env names, else the job’s own the rollouts cron
    GitLab the rollout job in the pipeline the token_env variable a pipeline schedule with that cron and the variable TERRAGUCCI_SCHEDULE set to rollouts; init prints the steps

    token_env is the project’s forge token variable, shared beyond the rollout: on GitLab every job that pushes or opens a merge request reads it, and on GitHub and Forgejo the fmt, tips, version-bump and drift jobs export their own token under that name. respond.rollout: off leaves the rollout job out.

    Without rollouts, run the rollout again after each merge. Each run takes at most one step:

    Terminal window
    npx terragucci rollout modules/network 1.4.0 --mode apply

    Either way, the next wave waits for the last to merge and apply. The apply status it checks is apply/<path> per directory, else terragucci/apply. A pull request closed unmerged or a failed apply stops the rollout. It never merges or writes a default branch.

    Exit code Meaning
    0 a step was taken, or the rollout is complete
    3 a pull request waits for a merge or an apply
    1 the rollout stopped

    From a control repo, wave 1 holds every project’s canaries and later waves follow in config order. Each project gets its own pull request per wave. rollouts is a single repo’s key, since a project’s pipeline sees only its own roots; in a control repo, run terragucci respond rollout --mode apply on a schedule of your own.

The same flow moves a provider in the lock file:

Terminal window
npx terragucci rollout --provider hashicorp/aws 6.68.0 --mode apply

Each lock file is rewritten for that provider alone, and an exact version constraint moves too. The wave stops unless every other provider stays where it was.

A rollout starts when a person names a version. With rollouts.watch it also starts when a module or provider the roots use has a newer release. rollouts takes a map in place of the cron:

rollouts:
schedule: "*/15 * * * *"
watch:
- module: "terraform-aws-modules/*/aws"
follow: [patch, minor]
min_age: 3d
- provider: "hashicorp/*"
follow: [patch]

Each run of the rollout job continues the rollouts in flight, then reads the default branch for module calls that pin an exact version and the providers each lock file holds, and keeps the ones a rule names. A glob matches the address with or without its registry host, and * stays within one segment, so terraform-aws-modules/*/aws is every module of that namespace on the aws system and terraform-aws-modules/** is every one of them. The first rule that matches decides.

For each one, the watch asks the registry for its releases and takes the newest one the rule lets through: a bump in follow (patch and minor when unset, since a major release changes an interface), at least min_age old. A newer release that is held back does not stop an older one that qualifies. That release becomes the to of an ordinary rollout from the highest version a root pins, and the rest follows as above: one pull request per wave, the next only after the last applied.

  • A release with no date cannot meet min_age. The dates come from the registry’s version document (published_at), which the public registries serve; a static registry or an OCI repository gives none.
  • Registry modules, oci:// modules and providers are read. A git module is not, and the run lists it as skipped.
  • A module call whose version is a constraint such as ~> 5.0 is not followed. The constraint already floats, and a release outside it needs the constraint changed. terragucci pin modules turns constraints into exact pins, and the watch follows them from then on.
  • A module with a rollout in flight is left alone until it finishes, and a release whose rollout already ran is not started again. Roots still on an older version are named, with the command that moves them.
  • A dry run (terragucci respond rollout, without --mode apply) lists what each rule would start and why anything is held.

When a bot already opens the pull request for the same bump, that pull request is the canary wave. The watch looks at pull requests from renovate/ and dependabot/ branches whose title, branch or body names the module or provider and the new version:

The bot’s pull request The watch
open waits, and names it
merged, apply not reported waits
merged, apply failed stops, and starts nothing
merged and applied starts the rollout for the roots the bot did not move
closed without merging starts nothing for that release

The apply it reads is the one a rollout’s own waves read: apply/<path> checks per directory, else terragucci/apply, else the apply jobs. For the bot’s pull request to be a canary rather than the whole change, point it at the roots that go first:

.github/dependabot.yml
version: 2
updates:
- package-ecosystem: terraform
directories: ["/envs/dev/*"]
schedule: { interval: daily }
{
"packageRules": [
{ "matchManagers": ["terraform"], "matchFileNames": ["envs/dev/**"] }
]
}

Dependabot opens one pull request for each directory it is given, and Renovate’s matchFileNames limits a rule to the files it lists. Match them to waves.canary. A bot that bumps every root in one pull request leaves nothing for the rollout to stage, and the watch finds every root at the new version.

Without a soak, wave N+1 opens as soon as wave N applied. rollouts.soak holds it until the wave before it has had time to show a problem:

rollouts:
schedule: "*/15 * * * *"
soak:
duration: 24h
checks:
- { kind: drift, on_fail: hold }
- { kind: apply, on_fail: hold }
- { kind: policy, on_fail: hold }
overrides:
- module: "terraform-aws-modules/vpc/aws"
duration: 2h
- provider: "hashicorp/*"
duration: "0"

The soak takes the words of a stage’s environments.<name>.soak, chant’s soak: duration, and checks, each a kind and on_fail. on_fail: hold keeps the time already counted while a check fails, and restart, chant’s default, starts the soak over once it passes again. A rollout reads the kinds drift, apply and policy on its projects. after and conditions are the earlier spelling and still read: after is the duration, and each condition is a check with on_fail: hold.

soak: 24h alone is the same as soak: { duration: 24h }. The clock starts when the wave’s last pull request merged, and a run that finds the time not up opens nothing and says when the wave is due. No timer runs between jobs: the next run of the rollout job reads the time, as it reads everything else. The soak is the same in a dry run. A rollout whose earlier waves had nothing to move has no wave to soak.

Each check is read on the wave’s roots, and a finding holds the next wave until a later run finds none. Each kind runs when checks lists it:

Check kind Holds the next wave while
drift the project’s open drift issue names one of the wave’s roots
apply the newest apply on the default branch failed for one of them
policy a policy denial of one of them was recorded on the gate ledger since the wave merged

An override applies to the rollouts whose module or provider matches its glob, and the first one that matches decides. Its duration and checks replace the soak’s; one it leaves out stays as the soak has it. duration: "0" waits for the checks alone, or for nothing when there are none.

Each wave’s pull request says how the next one is held. The rollout’s output lists, under the wave that soaks, when the next wave is due and what it waits for.

A person with write access skips the soak by commenting /terragucci skip-soak on any pull request of the wave that soaks. The forge keeps the comment with its author and time. The next run that opens the wave records the skip on the gate ledger, as the approval of the wave’s soak gate with the commenter as approver, and names who skipped. A comment from anyone else counts for nothing. With a skip-soak list under comment_allow in the repository that runs the rollout, the author must also be on it or in one of its teams.

An app made from a template pins it exactly in its module "app" call, so the same flow moves it. Name the template by its address:

Terminal window
npx terragucci templates apps --template acme/bucket/aws
npx terragucci rollout acme/bucket/aws 1.3.0

The first command gives each app an upgrade: the newest active release above its pin that a request may name, so under templates.require: signed (the default) an unsigned release is never offered. Its yanked is true when the catalog pulled that pin. With templates set in terragucci.yml, the second speaks in apps:

  • Each wave’s pull request is titled by the apps it moves, such as Upgrade bucket to 1.3.0: orders (wave 1 of 2).
  • Its body lists those apps with the catalog’s changelog entries after the old pin.
  • The target passes the same signing check: under templates.require: signed a rollout to an unsigned release exits 1 and opens nothing, and with no version named it moves to the newest signed one.
  • An app on a yanked pin moves from it in the first wave after the canaries. One that reads another moving root’s state keeps its place in dependency order.

waves.canary takes app roots such as apps/orders. Start it with --mode apply or from the workflow; the schedule then opens each later wave. On GitHub and Forgejo the workflow’s dispatch takes two inputs:

Input Meaning
module the module or template, such as acme/bucket/aws; empty continues every one in flight, as the schedule does
version the release to move to; empty for the newest published
Terminal window
gh workflow run terragucci-rollout.yml -f module=acme/bucket/aws -f version=1.3.0

A dispatch that finds the wave still open, or its apply not yet reported, ends without failing. Without a readable catalog the run names roots instead of apps and adds a note.

A module kept in the repository and called by relative path (source = "../modules/network") has no version, so a change to it reaches every root that calls it in one commit. terragucci modules adopt moves each call to the source the module is published at, caller by caller, and an ordinary rollout takes over from there.

Publish the module first (see Publish modules). This command does not publish, and it stops with the steps when the version it needs does not exist. Then:

Terminal window
npx terragucci modules adopt modules/network --dry-run
npx terragucci modules adopt modules/network --mode apply

The first command lists each call of the directory, in a root or in another module, and the waves of roots it would open, without asking the forge for anything. The source comes from modules.publish (git-tags gives git::<origin>//modules/network?ref=modules/network/v<version>, an oci:// address gives its tag) or modules.registry, or from --source with the address and no pin. The version is the newest published, or --version.

For a git source, the command clones the tag and compares its files with the directory. A directory that differs from its release is refused with the files that differ, because the plan of each wave can show no changes only when they match. Each wave’s pull request changes the source line of its roots’ calls and no other byte, and its plan should show no changes. terragucci respond rollout opens the next wave once the last one has merged and applied. A call inside another module stays a relative path, since a rollout reads roots; a root with a call it cannot edit, such as a version argument beside the local source or a source built from an expression, is listed with the reason and left out.

When every wave has merged, terragucci rollout modules/network <version> moves the module like any other.

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.