Skip to content

Terraform lexicon: preview a hole member outside a composed group #4463

Open

Description

@lex00

Part of #4419 (ruling 6, 2026-10-25). Filed so it is tracked; the epic does not build it. #4419 is closed; this now sits under epic:engine-ship.

A Terraform component whose upstream outputs are unknown at plan time, and which does not join a composed group (it falls back, per ruling 1), is a hole today: it gets no plan until its upstream applies, and it needs its own approval. In code: plan returns waitingRoot(...) as soon as ctx.unresolvedInputs is non-empty (lexicons/terraform/src/components/capability-plugin.ts:313-314), since terraform takes no unknown variable (same file, lines 40-43).

AWS previews such a member with placeholders and re-checks the real change set on apply (#4423; cfnPlaceholder in lexicons/aws/src/components/apply.ts:342, used at line 459). Terraform could do the same: plan the root with placeholder values for the unknown reads, record the plan shape (#4436, terraformPlanShape, already returned by plan), and on apply compare the real plan against it through the lexicon contract (#4425), so one approval covers it when the shapes match.

Acceptance criteria

  • A Terraform root outside a group, with unknown upstream reads, gets a preview plan in the pull-request run.
  • On apply, the real plan is compared against the previewed shape; a match needs no second approval, a mismatch stops for one.
  • The report says the member was previewed with placeholders, and which reads were placeholders.
  • Each placeholder is typed from the root's variable block (a string, number, bool, list or map stand-in), asserted by a unit test per type.
  • A root whose placeholder plan cannot run is handled per the decision below, asserted by a test.
  • docs/src/content/docs/components/plan-previews.mdx:212, which says terraform-apply reports a hole for an unresolved reference, says instead that a root outside a group is previewed with placeholders, and the terraform-apply section (line 160) says what the preview covers.
  • A recorded pull-request run over a fixture with one fallen-back root reading another shows the preview and a single approval (maintainer run).

Depends on

#4436 (plan shape), #4447 (terraform-apply through core's interface). Both closed.

Open questions

  1. What happens when a Terraform root's placeholder plan fails, for example a validation block rejects the stand-in or a count or for_each depends on the unknown value?
    • (a) The member stays a hole as today, and the report says why the preview was not possible.
    • (b) The member is plan-failed, and the pull request cannot pass until its upstream applies.
      Recommended: (a), because the preview is an improvement over the hole, and a failed preview should not leave the member worse off than today.

Activity

  1. added
    enhancement
    area:terraform
    orchestration
    epic:engine-ship
    on Oct 25, 2026
  2. lex00 commented on Oct 26, 2026

    @lex00
    ContributorAuthor

    Maintainer rulings on this issue's open questions (2026-10-25, epic:engine-ship refinement):

    • When a Terraform root's placeholder preview plan fails (a validation block, or count/for_each on the unknown), what happens?
      Ruling: Stays a hole
  3. lex00 commented on Oct 26, 2026

    @lex00
    ContributorAuthor

    Merged into integration/engine-ship at 139eb32 (unit branch unit/es-chant-4463).

    What landed:

    • lexicons/terraform/src/components/placeholder-preview.ts (new). terraformPlaceholder types a stand-in from the root's variable block: known-after-apply for string/any/untyped, 0 for number, false for bool, [] for list and set, {} for map, one stand-in per element for a tuple and per attribute for an object (optional(t) read as t). markPlaceholderDriven reads the plan's configuration and marks every attribute whose expression references a stand-in variable (through module inputs too), plus any value carrying the known-after-apply string, as unknown after apply. Root outputs get the same treatment. No stand-in value reaches the change set, the shape or the digest.
    • lexicons/terraform/src/components/capability-plugin.ts: plan now previews a root with unresolvedInputs. It plans to .chant-preview.tfplan with text: false (pr-loop.tofu.test.ts five-roots cases sit at the 5s unit budget since plans run show -json #4479), deletes that file, and returns the marked change set, the planned outputs and a shape whose unknownInputs are the upstreams. The artifact is a terraform-apply-shape artifact, never a plan file. The digest is taken over the preview's shape and entries. Core's coveredRound covers the round after the upstream applies when it stays within the shape, so a match needs no second approval and a mismatch asks for one. A run handed the shape itself plans with the real values and throws PlanShapeMovedError (exit 3) on any difference, without applying.
    • Per the ruling, when no preview is possible the member stays a hole and the reason says why: inputs from <c>; planned again once they apply; no preview: <why>. That covers a root missing from terraform.roots, an undeclared variable, an unknown nested inside a larger value, a count/for_each that reads a stand-in, and a failed placeholder plan (the first lines of terraform's error, e.g. a validation block).
    • Report: ChangeSetMember.placeholders (new optional field in packages/core/src/change-set.ts and workspace/change-set.schema.json, documented in reference/change-set.mdx) lists the variables as var.<name>. The PR note's member row says previewed with placeholders for var.<name>, and the existing "Known only after apply" line still names the reads.
    • Docs: components/plan-previews.mdx (the terraform-apply section says what the preview covers and when it stays a hole, the Outputs paragraph no longer lists terraform-apply as reporting a hole, and the generated row is updated in scripts/plan-previews.ts too). guide/apply-on-merge.mdx gets one sentence.
    • Tests written, not run: placeholder-preview.test.ts (one test per type: string, number, bool, list, map, plus object and tuple; the no-preview reasons; marking through module inputs and outputs; the count refusal) and new cases in capability-plugin.test.ts (preview with placeholders, a failed placeholder plan stays a hole with the reason, a count over a stand-in, run applying a matching real plan, run refusing one that adds a resource). The two existing hole tests were updated for the new reason text.

    Decision recorded (no open question covered it): a stand-in that reaches an attribute by some other route (a number through a local) is not marked. The real plan then differs from the preview and asks for its own approval, so the cost is an extra round and never an unapproved apply.

    Still missing: the recorded pull-request run over a fixture with one fallen-back root reading another, showing the preview and a single approval (maintainer run). tsc --noEmit is clean on packages/core and lexicons/terraform, apart from the TS6059 rootDir noise that was already there.

  4. lex00 commented on Oct 26, 2026

    @lex00
    ContributorAuthor

    Epic-ready fix merged into integration/engine-ship at d02d65d (unit commit 33ac284).

    lexicons/terraform/src/components/pr-loop.tofu.test.ts went red once this unit landed: app reads a.id, so it is now previewed with placeholders instead of being a hole, and its round 2 plan is covered by the first approval. The code does what this issue's acceptance says, so the test changed: app has update 1, placeholders var.subnet and no hole in the first change set; on merge both roots apply in one run with round 2 covered (filledInputs a.id); the stored change set holds app's entry too. The test that approved a separate pr-apply-round-2 gate and resumed was removed, since this estate no longer reaches that state. The not-covered round and the resume path are still tested in core (pr-waves, pr-run, promote-rounds) but no longer over real tofu; a fixture whose round goes uncovered would bring that back if wanted.

  5. lex00 commented on Oct 26, 2026

    @lex00
    ContributorAuthor

    Ticked the six code items: on chant main e17daa8 (merge of integration/engine-ship, tree identical to tested tip 9ae806b; vitest --project unit 29243 passed, 0 failed). placeholder-preview.test.ts, capability-plugin.test.ts and pr-loop.tofu.test.ts (expectations updated in fix d02d65d: app is now previewed with a placeholder for var.subnet and its round is covered by the first approval) passed. Ready for the maintainer: the recorded pull-request run. On a workspace like pr-loop.tofu.test.ts's (a root outside a group reading another's output), run chant components pr-plan on the pull request and chant components pr-apply on the merge with chant built from main, and record that the note says "previewed with placeholders for var." and that the merge applies with one approval.

  6. lex00 commented on Oct 26, 2026

    @lex00
    ContributorAuthor

    Audit correction (2026-10-26): the ready comment named no fixture. Round 2's #4487 unit adds a fixture whose dependent's real plan exceeds its placeholder preview, and the recorded PR run for this issue should use pr-loop.tofu.test.ts's workspace shape. Exact steps follow when it lands.

    Main is now 1b233ff (tree equal to tested tip 991ca77; unit suite 29255 passed). The only change since e17daa8 is #4475's drift-record files.

  7. lex00 commented on Oct 26, 2026

    @lex00
    ContributorAuthor

    The fixture for this issue's recorded pull-request run landed with #4487 (merge 1fe37d6 on integration/engine-ship): lexicons/terraform/src/__fixtures__/pr-loop/. Its README.md gives the steps; the a-v2 pull request is the single-approval path (app previewed with placeholders for var.subnet, covered on merge). The a-wide path in the same README is #4487's uncovered round. The run stays the maintainer's.

  8. lex00 commented on Oct 26, 2026

    @lex00
    ContributorAuthor

    Ready for the maintainer (epic:engine-ship round 2, 2026-10-26).

    chant main is 9b8fa99 (the merge of integration/engine-ship, tree equal to the tested tip 280be4e; unit suite 29365 passed, 2 budget-only failures under load, no assertion failure). Push CI on main passed (chant run 40407754959).

    Left: the (maintainer run) item, the recorded pull-request run. The fixture is lexicons/terraform/src/fixtures/pr-loop/ (from #4487, merge 1fe37d6), and its README has the steps. Use the a-v2 path. pr-loop.tofu.test.ts, placeholder-preview.test.ts and capability-plugin.test.ts passed on 280be4e.

    With chant from main 9b8fa99 and tofu (or terraform) on PATH, in a scratch copy of that directory:

    1. git init -b main. Add a .gitignore listing node_modules, .terraform, .terraform.lock.hcl, *.tfstate*, chant.tfplan and .chant, then commit.
    2. Write all.json as {"changed":["net","dns"]} and run chant components fan-out --from-affected all.json.
    3. On a branch, change a-v1 to a-v2 in roots/a/main.tf and commit. Run chant components pr-plan --base main --pr <n> --forge github. The note's app row should say previewed with placeholders for var.subnet.
    4. Approve the digest the note names, using the line the note prints (chant approve pr-<n> pr-apply --plan <digest> --approver github:<your-login> --sign). Merge, then run chant components pr-apply --base <main before the merge> --forge github --require-review. Both roots should apply in one run, with app's round covered by the first approval and a.id filled in.

    Every root uses terraform_data with local state, so this needs no cloud and no emulator. Post the note and pr-apply's output here.

  9. lex00 commented on Oct 27, 2026

    @lex00
    ContributorAuthor

    Ready for the maintainer (consolidation-graph, 2026-10-27)

    chant main is now 47b8594 (tree equal to the tested tip b6281ef; full unit project green there, 30275 tests, including pr-loop.tofu.test.ts, placeholder-preview.test.ts and capability-plugin.test.ts).

    Left: the (maintainer run) item, the recorded pull-request run over lexicons/terraform/src/fixtures/pr-loop. A correction to the round-2 comment, which said this needs no cloud: the roots are local, but --forge github posts to and reads a real GitHub pull request, and --require-review needs an approving review from a second GitHub account. So the run sheet puts it with the real-service runs. It costs nothing and touches no cloud. One thing to check before running: whether --sign on the approve line needs a configured signing key.

    Commands: run sheet entry H1 in Run sheet: engine-wt/goals/consolidation-graph-1-runs.md.

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

    area:terraformenhancementepic:engine-shiporchestration

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions