Promote a release through environments
Optional: hand this page to your coding agentThe steps work by hand too.Show the whole prompt
Read https://intentius.io/terragucci/guides/promote-a-release/.
Read terragucci.yml, chant.config.ts and terragucci.component.ts in this repo, and tell me the promotion order, the root each component applies in each environment, and which environments wait for an approval.
Read only: do not run terragucci promote, terragucci rollback or chant release cut.
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”A release holds the files of one commit for each environment. It moves through the environments in the order promotion lists. Staging gets the staging roots’ files only, never dev’s. A person approves each release once for an environment with a gate. terragucci rollback puts an earlier release back in one environment, behind the same gate.
chant/lifecycle records each deploy with the release, the person who ran it and the approver.
Prerequisites
Section titled “Prerequisites”| You need | Why |
|---|---|
A repo of plain roots, with one root per environment for each part, such as envs/dev/network and envs/prod/network |
each environment applies its own roots. Terragrunt units and Atmos instances are not deployed this way |
environments naming each environment’s roots |
promotion lists environments by name |
A backend that is not local for each root |
a release deploys a recorded copy of the root’s files, which reads its state from the backend |
@intentius/chant-lexicon-terraform installed beside terragucci, at the version terragucci promote names when it finds none |
a deploy applies each root with the terraform lexicon’s terraform-apply step |
-
Set the order in
terragucci.yml:environments:dev: { roots: ["envs/dev/**"], gate: never }staging: { roots: ["envs/staging/**"], gate: always }prod: { roots: ["envs/prod/**"], gate: always }promotion: [dev, staging, prod]Run
npx terragucci initand commit what it writes.chant.config.tslists the environments in that order,terragucci.component.tsholds each root as a component (The components), and.chant/pipeline.tshas one stage per environment. After a change toterragucci.yml,npx terragucci ciwrites the pipeline again.From then on, each merge applies dev and then cuts a release of the merge commit, labelled with the next version; the apply job’s log names it.
chant.config.tsalso setsrelease: { green: "forge-checks" }. The cut’s green gate is then the merge commit’s checks on the forge, among them thecheckjob and the earlier wave jobs of the run that applies: it waits while they run and cuts once they pass, reading them with the apply job’s forge token, so the repository needs noci/greentag. On GitHub the apply jobs get read access to checks, statuses and actions for it. Whenchant.config.tsis the repo’s own,initnames the line to add. Steps 2 and 3 are forrelease: { cut: false }, or a release of another commit. -
Cut a release from a commit of the default branch whose checks passed, in a clean checkout of that commit:
Terminal window GH_TOKEN=$(gh auth token) npx chant release cut v1.4.0 --yesgit push origin release/v1.4.0The cut records each environment’s roots as they are at that commit. Without
--yesit prints what it would record and records nothing. -
Deploy the release to the first environment:
Terminal window npx chant run --components all --env dev --release v1.4.0 -
Promote it to the next environment:
Terminal window npx terragucci promote --to staging --release v1.4.0 --dry-runnpx terragucci promote --to staging --release v1.4.0--dry-runprints the plan and changes nothing. Under a gate, the promote stops at the staging stage and exits 3:error: tf-apply staging waits for an approval of jcs1-sha256:fc692c3f… [pipeline-gate-waiting]Approve it with: terragucci approve release staging -
A reviewer approves the release for staging. Then the same promote applies:
Terminal window npx terragucci approve release stagingnpx terragucci promote --to staging --release v1.4.0The approval holds for that release in staging, and the promote spends it. Nothing else waits, so the promote applies straight after it.
-
Repeat for
prod. A promote that skips an environment, such as--to prodwhile staging has not run the release, is refused;--allow-skiplets it through.
Roll an environment back
Section titled “Roll an environment back”npx terragucci rollback prod --release v1.3.0 --dry-run
npx terragucci rollback prod --release v1.3.0prod gets the files v1.3.0 recorded for it. The rollback waits for one approval like a promote: approve it with terragucci approve release prod and run the same rollback again. The deploy record then names v1.3.0 as the version prod runs. With pause_after_rollback on prod, the rollback then pauses the stage until terragucci resume prod.
The components
Section titled “The components”init names each root’s component by its path with the segment that names its environment taken out: envs/dev/network and envs/prod/network are both envs-network. A promote to staging takes envs-network as dev recorded it and applies envs/staging/network. A root whose path has no segment named for its environment keeps its whole path as its name, and init says so when a later environment has a component the one before it lacks.
An environment waits for one approval unless its gate is never. With no gate of its own, it takes the top-level gate. That approval belongs to the environment’s stage in .chant/pipeline.ts. init writes the pipeline and the components from one terragucci.yml, so they agree on which environments wait. A promote asks before it plans, so on-destructive asks on every promote.
A promote or rollback reads .chant/pipeline.ts on the default branch first, as chant does, so push the pipeline with the components. When .chant/pipeline.ts is the repo’s own, init keeps it and adds a gate step to the components for each environment that waits.
Keep later environments to promotes
Section titled “Keep later environments to promotes”The pipeline a merge runs is the same with or without promotion: it applies what a pull request changed in every environment. To have staging and prod change only through a promote, route their roots to a branch nobody pushes with apply.branches, so a merge applies dev alone:
apply:
branches:
release: ["envs/staging/**", "envs/prod/**"]terragucci promote lists every flag.
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.