Skip to content

test: pin parameter, preset and tag values that flow from resources - #223

Merged
Emyrk merged 3 commits into
mainfrom
resource-closure-test-vectors
Sep 10, 2026
Merged

test: pin parameter, preset and tag values that flow from resources#223
Emyrk merged 3 commits into
mainfrom
resource-closure-test-vectors

Conversation

@Emyrk

@Emyrk Emyrk commented Sep 2, 2026

Copy link
Copy Markdown
Member

Pins the parameter, preset, and tag values that flow from resource blocks, ahead of #221 (which evaluates only the parameter/preset/tag closure via coder/trivy#74). Everything passes on main, where nothing is pruned, so a failure after rebasing #221 means pruning dropped a resource a target depends on.

Prepared with Coder Agents assistance.

Baseline vectors for any evaluation strategy that skips resource blocks
(coder/trivy#74, #221). Covers direct, local, indexed,
transitive, conditional, try(), nested option and dynamic blocks,
meta-arguments, data-source intermediaries, module inputs, and a JSON
template with two resources in one expression.
@Emyrk
Emyrk marked this pull request as ready for review September 10, 2026 13:37
Revives the diskaccess fixture from #85 against the current harness: the
in-tree file is read and used as the default, the escaping path yields an
unknown option and an invalid-options diagnostic.
@Emyrk
Emyrk requested a review from geokat September 10, 2026 13:45
Revives the chain fixture from #164. The first hop (a parameter
count-gated on another's value) works. The second hop, count-gated on a
count-gated parameter's value via [0], does not: the count is evaluated
before the input flows in and expansion is not revisited, so cpu_cores is
dropped. The vector pins that and documents how to flip it once fixed.
@Emyrk
Emyrk merged commit 76a8ca4 into main Sep 10, 2026
4 checks passed
@Emyrk
Emyrk deleted the resource-closure-test-vectors branch September 10, 2026 14:37
Emyrk added a commit that referenced this pull request Sep 11, 2026
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.
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).
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