Skip to content

Roll back a Terraform root to a named release: record root trees in release cut, plan them on promote and rollback --release #4542

Closed

Description

@lex00

Reader problem

From a Hacker News comment the blog draft answers: "rollback would be targeting the last revision at the service level". The draft post on branch draft/agents-propose-ci-applies of lex00/lex00.github.io shows chant release cut, chant components promote --release and chant components rollback --release as the way to roll back to a named release. Today that works for components that publish an artifact or deploy templates, and the post says Terraform roots roll back through chant lifecycle rollback --to instead. This issue is the gap that keeps the post from saying "every component".

What exists today (chant 930cb99)

  • Promote, rollback and redeploy strip build steps and refuse a component with no publish step unless the release recorded its templates: packages/core/src/components/promote.ts:522 ("has no publish step, so nothing in its deploy carries a recorded digest").
  • templatesPinned comes from releaseTemplatesDigest (packages/core/src/components/release-promote.ts:68), which reads only target.templates (the template, manifest and values fields).
  • terraform-apply names its root by key (root: "net"), and DEPLOY_INPUT_FIELDS (packages/core/src/components/deploy-inputs.ts:47) has no entry for it, so a release records no copy of a root's files and chant components rollback prod --release v1.4.0 refuses a Terraform-only component.
  • terraform-apply declares rollbackPolicy: "needs-opt-out" (lexicons/terraform/src/components/capability-plugin.ts:430): undoing an apply is applying the previous configuration.
  • chant lifecycle rollback [env] --to <ref> (packages/core/src/lifecycle/rollback.ts) opens a pull request restoring sourceDir, which covers a root in source but outside the release model.

What's missing

  1. A release cut records each terraform-apply root's files (the root directory, its local modules and var files, the same set the pull-request plan treats as the root's change) as a tree, as components: bind a gate's plan digest to the contents a non-planning step deploys, so a change after review needs a new approval #4155 does for other deploy inputs.
  2. promote --release and rollback --release point the step at the recorded root, plan it against the environment, and bind the gate to that plan, so rolling back is a new plan of the old configuration under its own approval.
  3. The same for a Pulumi/plunge stack once it is a component (see the companion chant issue for a Pulumi deploy capability).

Acceptance criteria

  • chant release cut records a terraform-apply component's root tree; chant release list/verify show it.
  • chant components rollback prod --release <label> on a project of Terraform roots plans each root at the release's recorded files, waits at the release gate with that change set, and applies it on approval.
  • chant components rollback prod --component net restores the previous recorded release of a root, with the same plan-and-gate step.
  • A rollback whose plan is empty passes without an approval, as an empty change set does today.
  • Docs (cli/components.mdx, cli/release.mdx) say which capabilities roll back by release, with Terraform included.

Activity

  1. added
    epic:ci-products
    epic:plywood
    on Oct 27, 2026
  2. lex00 commented on Oct 27, 2026

    @lex00
    ContributorAuthor

    Items 1 and 2 (the Terraform part) merged into integration/ci-products at eb8e081 (unit branch unit/cp-chant-4542, commit b848a0e). Compile check only; nothing was run.

    Behaviour on the branch:

    • Core gains an optional capability method, releaseInputs(input, { memberDir }) (packages/core/src/components/capability.ts). It answers the files a step deploys from when its input names them by key, the field to point at the copy, and the directory the step runs in, or { unbound: reason }.
    • terraform-apply answers it from lexicons/terraform/src/components/release-inputs.ts: the root's directory and the local modules it reaches (rootWatchPaths, the set the pull-request plan uses), plus var files and backend-config files. A root on the local backend is unbound, because a plan run in a copy would read no state. Such a root still rolls back through chant lifecycle rollback --to.
    • release cut (compileEnvironment in packages/core/src/components/release-compile.ts) records those files for the component and lists each directory in the target's trees. An unbound step, or one that reads a path outside the member directory, is left out and the cut prints the reason. The cut dry run now lists each recorded tree, and release list --json already includes trees.
    • Under a release, pinReleaseTemplates (packages/core/src/components/release-promote.ts) writes every file the target records for the component to .chant/release-templates/<layout digest>/ at its member-relative path, so ../modules/x still resolves. It then sets the step's dir to the copy of the root. terraform-apply and the activities take dir in place of the entry's dir (resolveRoot in lexicons/terraform/src/op/activities/terraform.ts) and keep the entry's workspace, var files, backend config and estate. The existing release gate binds the plan of that copy. Because the release records the component's templates, templatesPinned holds and the Terraform-only component is no longer refused.
    • components rollback <env> --component <name>: when the record being restored has digestKind: "templates" and a releaseDigest, the rollback now runs under that release, so the root goes through the same plan-and-gate step (runComponentsRollback in packages/core/src/cli/handlers/promote.ts). Template-only cfn-deploy components also get this path.
    • groupFallback keeps any member pointed at a recorded copy out of a composed group, because the composition reads the declared roots.
    • Docs updated: cli/release.mdx (components: bind a gate's plan digest to the contents a non-planning step deploys, so a change after review needs a new approval #4155 section) and cli/components.mdx (which capabilities roll back by release, and --component for a template-only record).

    Still to do:

    • Item 3 (Pulumi/plunge stacks) is not part of this unit. It waits on Pulumi and plunge stacks as components that plan and apply, so plywood can run them #4541, which adds the Pulumi apply capability; once that lands, the stack only needs to answer releaseInputs.
    • All five acceptance boxes need a run (cut, rollback by release and by component, empty-plan pass), so none is ticked. They wait for epic-ready. No tests were added or run.
    • The path set the copy is pinned to comes from the member directory. A project whose chant.config.* lives above the member directory would resolve dir against the wrong base. That layout is unusual for chant members and is not handled.
  3. lex00 commented on Oct 28, 2026

    @lex00
    ContributorAuthor

    Item 3 (Pulumi and plunge stacks) merged to integration/ci-products at 745afb0 (unit branch unit/cp-chant-4542, commit 3e966e3 and a merge commit that runs the install through #4592's pinned binary). Compile check only: npm ci, scripts/ci-lexicon-artifacts.sh --steps generate,bundle and npx tsx scripts/typecheck.ts pass with no regressions, and the docs prose lint shows 0 regressions on the merged tree. Nothing ran pulumi or plunge; the tests use a fake runner and were not run.

    Behaviour on the branch:

    • Rollback by release for stacks rides on Pulumi and plunge stacks as components that plan and apply, so plywood can run them #4541's releaseInputs with no core change. pulumi-up answers the stack's directory (plus main when it points outside it), the cut records its tracked files, and under a release core points the step's dir at the copy in .chant/release-templates/<digest>/. promote --release, rollback --release and rollback --component (for a templates record) then preview the recorded program against the stack and bind the release gate to that preview, the same path Roll back a Terraform root to a named release: record root trees in release cut, plan them on promote and rollback --release #4542 gave Terraform roots. A stack whose backend is a file:// path relative to its directory stays unbound and is printed by the cut.
    • The gap Pulumi and plunge stacks as components that plan and apply, so plywood can run them #4541 reported: a release copy of a Node program has no node_modules. I chose an install step in the copy, with a refusal by name where an install would not reproduce the release. lexicons/pulumi/src/release-copy.ts prepareReleaseCopy runs before the copy's first preview, in both plan and run, once per copy per process. It runs exactly pulumi install (plunge install on plunge, through the step's pinned binary when it sets engineVersion). That is the CLI's own install of dependencies and plugins, and it follows Pulumi.yaml's runtime options. It runs only when needed:
      • nodejs with no node_modules in the copy. A Node copy with no recorded lockfile (package-lock.json, npm-shrinkwrap.json, yarn.lock, pnpm-lock.yaml, bun.lock, bun.lockb) is refused with PulumiReleaseCopyRefusedError, because an install would take today's versions rather than the release's.
      • python with options.virtualenv naming a missing directory, or a poetry or uv toolchain.
      • go, dotnet, java and yaml never install. A directory outside a release copy is never touched.
    • Allowlist: PULUMI_INSTALL_COMMANDS and runReleaseInstall in lexicons/pulumi/src/run.ts accept install with no flag and nothing else.
    • Docs: cli/components.mdx now lists pulumi-up among the capabilities that roll back by release, and drops "A Pulumi stack does not roll back by release yet". cli/release.mdx describes what a pulumi-up step records and the install in the copy. The lexicon README is updated too.

    Tests written, not run: release-copy.test.ts (copy detection, one install for a Node copy with a lockfile, refusal with no lockfile and nothing run, the Python cases, Go and YAML never installing, a non-copy left alone, the install argv refusals).

    Still missing:

    • The acceptance boxes for stacks need a run: a cut that records a stack, and a rollback by release on floci that previews the copy, waits at the gate and applies. They wait for epic-ready, and none is ticked.
    • pulumi install on a Node program runs the package manager's install against the recorded lockfile. Whether it ever rewrites the lock under 3.272 is unchecked, and the recorded run should confirm it.
    • A Python program's pinning is not checked. A copy whose requirements are unpinned installs today's versions.
    • A stack whose Pulumi.<stack>.yaml is not tracked has no config in the copy, as for any untracked file.
  4. lex00 commented on Oct 29, 2026

    @lex00
    ContributorAuthor

    Close-out (2026-10-29)

    On main: eb8e081 (release cut records terraform-apply roots; promote and rollback under a release plan the recorded copy, rollback --component), 745afb0 (the same for Pulumi and plunge stacks through releaseInputs, with the install in the copy). Docs are in cli/release.mdx and cli/components.mdx, which now list pulumi-up and Terraform among the capabilities that roll back by release.

    All five boxes are ticked on the code, tests and docs on main (release-compile.ts and its test, release-promote, handlers/promote and promote.test.ts, lexicons/terraform release-inputs, lexicons/pulumi release-copy). No floci run was made.

    Closing: the described work is on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic:ci-productsepic:plywood

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions