Commit Graph
11 Commits
Author SHA1 Message Date
Steven Masley d544f394d4 fix(coderd): keep parameter values when the render is incomplete (#29108)
Closes #29099 ([ENG-3324](https://linear.app/codercom/issue/ENG-3324)).
Follow-up to #29102, which stopped the loss propagating through stop
builds but left start builds truncating.

## What this does

A render carrying a `module_not_loaded` diagnostic could not see the
whole template, so a parameter's absence from it is not evidence the
template stopped declaring that parameter. Keep the unmatched values
instead of deleting them.

## Why preserve rather than fail

provisionerd resolves modules itself, so only coderd's render is
degraded. Keeping the value produces a correct apply and the workspace
keeps building. Failing the build would turn silent data loss into an
inability to start every workspace on an affected template version.

A complete render is still authoritative and still narrows the set, so
unrelated warnings and legitimate parameter removals behave exactly as
before.

## Tests

- `TestResolveParameters/IncompleteRender`: complete render drops,
`module_not_loaded` preserves previous and build values, unrelated
warning drops.
- `TestDynamicParametersModuleCachePurged` now continues into the start
build. On `main` it fails with `start build must not drop the module
parameter`.

<details>
<summary>Notes for the reviewer</summary>

### Detection

`preview` tags the warning with `types.DiagnosticCode(diag,
types.DiagnosticModuleNotLoaded)`, so the check is
`previewtypes.ExtractDiagnosticExtra(diag).Code ==
previewtypes.DiagnosticModuleNotLoaded` over the second render's
diagnostics. Adding future completeness codes is a one-line change in
`incompleteRender`.

### Departure from the issue's sketch

The issue proposed also gating on `v.Source != sourceDefault`, to keep
discarding values that only ever came from a default. That check cannot
fire: `sourceDefault` is only assigned to parameters present in the
render output, so an unmatched value is never default-sourced. A default
stored by an earlier build arrives as `sourcePrevious` and is
indistinguishable from user input at this layer. The condition is
omitted rather than left in as dead code.

### Not covered

Nothing surfaces the degraded render to the operator. `wsbuilder` has no
logger, and `render.go` still discards preview's diagnostics (`Logger:
slog.New(slog.DiscardHandler)`). That is the follow-up work listed in
the issue.

</details>

---

🤖 Authored by Coder Agents on behalf of @Emyrk.
2026-09-08 17:20:53 +00:00
Steven Masley 36ea6eaf80 fix(coderd): do not narrow the parameter set on non-start builds (#29102)
Fixes part of #29099
([ENG-3324](https://linear.app/codercom/issue/ENG-3324)).

## What this does

Only a start build may narrow the stored set. A stop or delete build
does not change which parameters a workspace has.

## Why

A stop or delete build re-resolves the workspace parameters and deletes
every stored value the render did not return.

- When a template version's `cached_module_files` is NULL the renderer
cannot load modules, and the parameters are dropped. Any `restart` or
`coder update`, uses the broken version for `stop` and all parameters
are removed before the fixed `start`.
  - This can happen on any broken template version

## Scope

This does not fix a start build that resolves against a version with a
NULL module cache, which still truncates. That is the completeness-aware
discard loop described in the issue, and it lands separately.

## Tests

- `TestResolveParameters/UnmatchedValues` covers all three transitions
at the resolver level.
- `TestDynamicParametersModuleCachePurged` is an end-to-end regression
test: create a workspace with a module declared parameter, remove the
module cache, stop, and assert the value survives. It fails on `main`.

<details>
<summary>Implementation plan</summary>

### Problem

`dynamicparameters.ResolveParameters` ends with an unconditional discard
loop (`coderd/dynamicparameters/resolver.go`) that deletes every stored
value whose parameter is absent from the render output. With a NULL
module cache the render is incomplete, `preview` reports
`module_not_loaded` at warning severity, and the reduced parameter set
is treated as authoritative.

`wsbuilder.getParameters()` is transition-agnostic, so a stop build
persists that truncated set. `cli/update.go` stops first against the
workspace's current version, then starts against the active version, and
the start build reads the truncated set via `getLastBuildParameters()`.

### Coverage

| Case | Fixed here |
|---|---|
| `coder update`, old version purged, active version healthy | yes |
| Workspace sits on a purged version, autostop then autostart | no,
needs the discard loop fix |
| `require_active_version` where the active version is purged | no,
needs the discard loop fix |

### Changes

1. `resolver.go`: gate the discard loop on the build transition.
Ephemeral trimming, immutability, monotonicity, and default backfill are
unchanged.
2. `wsbuilder.go`: pass `b.trans`. Single non-test caller.

### Deliberate calls

- `delete` is treated like `stop`. Neither transition changes which
parameters a workspace has, and it keeps the condition to one
comparison.
- The transition is passed rather than a second boolean flag, so the
call site stays unambiguous next to `firstBuild`.

</details>

---

🤖 Authored by Coder Agents on behalf of @Emyrk.
2026-09-08 11:01:59 -05:00
Zach ddc0e99c69 chore: remove coder_secret Terraform integration (#25512)
Removes the coder_secret Terraform integration: the data.coder_secret
consumption path through provisionerdserver → provisioner.proto →
provisioner/terraform, the dynamic-parameter secret-requirement
validation, and the workspace-update / resolve-autostart surfaces that
depended on it. This is being done due to a product/feature direction
change (see PLAT-243). User-secret CRUD (DB, REST, CLI, UI, telemetry, audit)
and the agent-manifest secret-injection path are untouched.

The provisionerd API is bumped from v1.17 to v1.18 rather than rolled
back: v1.17 shipped in v2.33.x, so user_secrets field numbers are
reserved and the changelog documents both versions.

Generated with assistance from Coder Agents.
2026-05-21 09:19:29 -06:00
dylanhuff-at-coder fb84e72319 feat: add secret requirement contract to dynamic parameters (#24785)
Adds structured `secret_requirements` to dynamic parameter responses and
enforces missing required secrets during workspace start.

Stop, delete, and tag rendering paths skip secret requirement
enforcement so unmet secrets do not prevent cleanup. The SDK, generated
API docs/types, and backend render/resolver/wsbuilder tests are updated
for the new contract.
2026-04-29 16:38:26 -07:00
Steven Masley cc6766e64a chore: apply monotonic validation to workspace builds (#23180)
Still not applying at the dynamic parameters websocket. The wsbuilder is
the source of truth for previous values, so this is the most accurate
and still will fail in the synchronous api call to build a workspace.
This mirrors how we handle immutable params.

Closes https://github.com/coder/coder/issues/19064
2026-03-19 14:05:34 -05:00
Steven Masley 00ba0278d2 chore: modify parameter dynamic immutability behavior (#18583)
Immutability behavior is determined by the current build, not affected by the previous
2025-07-09 08:45:24 -06:00
Steven Masley a099a8a25c feat: use preview to compute workspace tags from terraform (#18720)
If using dynamic parameters, workspace tags are extracted using
`coder/preview`.
2025-07-03 14:35:44 -05:00
Steven Masley 699dd8e554 chore: create interface for pkgs to return codersdk errors (#18719)
This interface allows it to create rich codersdk errors and pass them up to the `wsbuilder` error handling.
2025-07-03 08:33:45 -05:00
Steven Masley e396b06c25 feat: allow new immutable parameters for existing workspaces (#18579)
Closes https://github.com/coder/coder/issues/18578
2025-06-25 15:41:53 +00:00
Steven Masley 5ed0c7abcb chore: improve dynamic parameter validation errors (#18501)
`BuildError` response from `wsbuilder` does not support rich errors from validation. Changed this to use the `Validations` block of codersdk responses to return all errors for invalid parameters.
2025-06-23 15:08:18 -05:00
Steven Masley 82af2e019d feat: implement dynamic parameter validation (#18482)
# What does this do?

This does parameter validation for dynamic parameters in `wsbuilder`. All input parameters are validated in `coder/coder` before being sent to terraform.

The heart of this PR is [`ResolveParameters`](https://github.com/coder/coder/blob/b65001e89c0577199a8e470c138c51e91cf2350c/coderd/dynamicparameters/resolver.go#L30-L30).

# What else changes?

`wsbuilder` now needs to load the terraform files into memory to succeed. This does add a larger memory requirement to workspace builds.

# Future work

- Sort autostart handling workspaces by template version id. So workspaces with the same template version only load the terraform files once from the db, and store them in the cache.
2025-06-23 12:35:15 -05:00