Skip to content

test: pin more evaluation paths from parameters to resources - #224

Merged
Emyrk merged 1 commit into
mainfrom
resource-closure-vectors-2
Sep 11, 2026
Merged

Emyrk merged 1 commit into
mainfrom
resource-closure-vectors-2

Conversation

@Emyrk

@Emyrk Emyrk commented Sep 11, 2026

Copy link
Copy Markdown
Member

Follow-up to #223. Pins more of the evaluation paths a parameter, preset, or tag can take to reach a resource, ahead of #221. All pass on main, and on #221 with the trivy pin at coder/trivy#74's current head (fc995ac).

  • testdata/resourceclosure2: validation block text and regex from a resource (asserted with a failing input), [for ...] and {for ...} over count and for_each resources, a splat directly in a tag, a count = 0 resource behind try(), a resource whose for_each is driven by a parameter value and is read by a tag, a computed attribute (stays unknown), a two-level module.outer -> module.inner chain, and three-hop locals.
  • testdata/resourceclosuresubmod: the only parameter is in a submodule and reads a root resource through a module input; the root has no target block at all.

Prepared with Coder Agents assistance.

Second batch alongside resourceclosure: validation blocks, for
expressions, a splat in a tag, a count = 0 resource behind try(), a
resource whose for_each is driven by a parameter, a computed attribute,
a two-level module chain, multi-hop locals, and a template whose only
parameter lives in a submodule.
@Emyrk
Emyrk merged commit 7e36784 into main Sep 11, 2026
4 checks passed
@Emyrk
Emyrk deleted the resource-closure-vectors-2 branch September 11, 2026 14:40
PushTheLimit added a commit to PushTheLimit/preview that referenced this pull request Sep 11, 2026
Preview evaluates the entire Terraform module graph on every call, even though
rendering a workspace form only needs coder_parameter, coder_workspace_preset
and coder_workspace_tags (and what they reference). The resources a workspace
would create cannot feed those blocks, so evaluating them is wasted work that
dominates request latency on large templates.

Pass OptionWithResourceClosure with the three target block types so the parser
drops root-module resources that nothing in that closure references. On a real
template this cuts EvaluateAll from ~2s to ~0.16s (~12x) with byte-identical
parameters, presets and tags.

Uses the OptionWithResourceClosure addition merged in coder/trivy#74; the trivy
replace points at that merged commit. Correctness is guarded by the resource
closure test corpus already in main (coder#223, coder#224).
Emyrk added a commit that referenced this pull request Sep 15, 2026
…#226)

Evaluates only the `coder_parameter` / `coder_workspace_preset` /
`coder_workspace_tags` closure when rendering, with an opt-out.
Supersedes #221 (thanks @PushTheLimit); the trivy side is
coder/trivy#74.

- Bumps the trivy pin to a commit with `OptionWithResourceClosure`, and
passes it by default so root resources nothing in the closure references
are skipped. On the motivating template `EvaluateAll` drops from ~2s to
~0.16s.
- `Preview` takes `opts ...Option`. `OptionFullEvaluation()` evaluates
every resource, so coderd can turn the optimization off behind a setting
without a new preview release if a template misbehaves.
- `Test_Extract` runs every vector in both modes against the same
expectations, pinning that parameters, presets, tags, and variables are
identical either way. `Test_OptionFullEvaluation` observes the
difference through `Output.ModuleOutput`.

Behavior notes:

- `Output.ModuleOutput` may contain unknown values for root outputs that
read pruned resources. Nothing in coderd consumes it.
- Templates containing `.tf.json` files skip pruning entirely (trivy's
JSON reference extraction is not reliable enough to prune on).

Test coverage for the reference shapes the pruner must see through
landed separately in #223 and #224.

Prepared with Coder Agents assistance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants