Commit Graph
32 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
Zach e0be9bf213 feat: surface missing coder_secret requirements on resolve-autostart (#25081)
Adds `dynamicparameters.EvaluateSecretMismatch` as a shared helper on
top of the existing renderer, then wires it into the resolve-autostart
handler so the UI can surface unsatisfied `coder_secret` requirements in
a template alongside parameter mismatch for autostart.

The lifecycle executor changes will land in a follow-up that depend
on this helper. The UI changes that consume the new `secret_mismatch`
field is also a follow-up.

Generated with assistance from Coder Agents.
2026-05-13 14:20:02 -06:00
dylanhuff-at-coder 6a200a49d3 feat: refresh dynamic parameters on secret changes (#24786)
Publishes user secret create, update, and delete events and subscribes
dynamic parameter websockets to authorized owner secret changes.

Secret changes trigger fresh renders with monotonic response IDs, with
backend tests covering subscription authorization and websocket refresh
behavior.
2026-05-06 09:27:24 -07: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 6b3d4377c3 feat: archive modules in size order until limit is hit (#21773)
Archiving modules attempts to save as many modules as it can before it hits the limit. Enabling the template as much as it can, rather than a hard failure.
2026-02-02 09:03:18 -06:00
1320b8d5be feat: make dynamic parameters opt-in by default for new templates (#19006)
resolves #18975 

---------

Co-authored-by: Steven Masley <stevenmasley@gmail.com>
Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
2025-07-28 20:41:49 -05:00
Steven Masley aedc019b4e feat: include template variables in dynamic parameter rendering (#18819)
Closes https://github.com/coder/coder/issues/18671

Template variables now loaded into dynamic parameters.
2025-07-21 13:02:31 -05: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 f6e4ba6ed9 chore: remove per request dynamic parameters opt in and rely on template (#18505)
When in experimental this was used as an escape hatch. Removed to be
consistent with the template author's intentions

Backwards compatible, removing an experimental api field that is no longer used.
2025-06-23 15:04:09 -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
Steven Masley 9b5d49967c chore: refactor dynamic parameters into dedicated package (#18420)
This PR extracts dynamic parameter rendering logic from
coderd/parameters.go into a new coderd/dynamicparameters package. Partly
for organization and maintainability, but primarily to be reused in
`wsbuilder` to be leveraged as validation.
2025-06-20 13:00:39 -05:00
Jaayden HalkoandSteven Masley 9a432b8d9f fix: add workspace owner id as query param to websocket (#18363)
Co-authored-by: Steven Masley <stevenmasley@gmail.com>
2025-06-13 14:49:32 -04:00
Jaayden HalkoandSteven Masley 5944b1c595 chore: remove local storage based optin/optout (#18344)
This removes the opt-in and opt-out buttons for dynamic parameters on
the create workspace page and the workspace parameters settings page.

---------

Co-authored-by: Steven Masley <stevenmasley@gmail.com>
2025-06-12 13:37:07 -04:00
f126931219 chore: remove dynamic-parameters experiment (#18290)
Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
Co-authored-by: jaaydenh <1858163+jaaydenh@users.noreply.github.com>
Co-authored-by: Steven Masley <stevenmasley@gmail.com>
2025-06-12 12:15:05 -04:00
Steven Masley fb63c9445c test: fix test flake in TestDynamicParametersWithTerraformValues (#18311)
Wrong build ID was being used for the await.

Closes https://github.com/coder/internal/issues/687
2025-06-10 16:13:47 -05:00
Steven Masley ca8660cea6 chore: keep previous workspace build parameters for dynamic params (#18059)
The existing code persists all static parameters and their values. Using
the previous build as the source if no new inputs are found.

Dynamic params do not have a state of the parameters saved to disk. So
instead, all previous values are persisted always, and new inputs
override.
2025-05-28 10:00:39 -05:00
Steven MasleyandJaayden Halko b4531c4218 feat: make dynamic parameters respect owner in form (#18013)
Closes https://github.com/coder/coder/issues/18012

---------

Co-authored-by: Jaayden Halko <jaayden.halko@gmail.com>
2025-05-27 15:43:00 -05:00
Steven Masley a123900fe8 chore: remove coder/preview dependency from codersdk (#17939) 2025-05-20 10:45:12 -05:00
Steven Masley f36fb67f57 chore: use static params when dynamic param metadata is missing (#17836)
Existing template versions do not have the metadata (modules + plan) in
the db. So revert to using static parameter information from the
original template import.

This data will still be served over the websocket.
2025-05-16 11:47:59 -05:00
ケイラ 60762d4c13 feat: load terraform modules when using dynamic parameters (#17714) 2025-05-13 16:07:29 -05:00
ケイラ 2cc56ab515 chore: fill out workspace owner data for dynamic parameters (#17366) 2025-04-17 14:51:50 -06:00
Marcin Tojek a7366a8b76 feat!: drop support for legacy parameters (#7663) 2023-06-02 11:16:46 +02:00
Ammar Bandukwala 95fb59696e Refactor Provisioner to distinguish Plan and Apply (#5036) 2022-11-11 16:45:58 -06:00
Mathias Fredriksson ccf6f4e7ed chore: Use contexts with timeout in coderd tests (#3381) 2022-08-09 20:17:00 +03:00
Steven Masley c9a4642a12 chore: Update BE http errors to be ui friendly (#1994)
* chore: More UI friendly errors

Mainly capitlization + messages prefix error
2022-06-03 21:48:09 +00:00
Spike Curtis d8c440188e feat: Remove organization and user scoped parameters (#2007)
* feat: Remove organization and user scoped parameters

Signed-off-by: Spike Curtis <spike@coder.com>

* Fixup dump.sql

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix dump.sql again

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix down migration

Signed-off-by: Spike Curtis <spike@coder.com>
2022-06-03 11:49:58 -07:00
Steven Masley 6c1117094d chore: Force codersdk to not import anything from database (#1576)
* chore: Force codersdk to not import anything from database (linter rule)
* chore: Move all database types in codersdk out
2022-05-19 13:04:44 -05:00
Steven Masley 591523a078 chore: Move httpapi, httpmw, & database into coderd (#568)
* chore: Move httpmw to /coderd directory
httpmw is specific to coderd and should be scoped under coderd

* chore: Move httpapi to /coderd directory
httpapi is specific to coderd and should be scoped under coderd

* chore: Move database  to /coderd directory
database is specific to coderd and should be scoped under coderd

* chore: Update codecov & gitattributes for generated files
* chore: Update Makefile
2022-03-25 16:07:45 -05:00
Kyle Carberry c451f4e685 feat: Add templates to create working release (#422)
* Add templates

* Move API structs to codersdk

* Back to green tests!

* It all works, but now with tea! 🧋

* It works!

* Add cancellation to provisionerd

* Tests pass!

* Add deletion of workspaces and projects

* Fix agent lock

* Add clog

* Fix linting errors

* Remove unused CLI tests

* Rename daemon to start

* Fix leaking command

* Fix promptui test

* Update agent connection frequency

* Skip login tests on Windows

* Increase tunnel connect timeout

* Fix templater

* Lower test requirements

* Fix embed

* Disable promptui tests for Windows

* Fix write newline

* Fix PTY write newline

* Fix CloseReader

* Fix compilation on Windows

* Fix linting error

* Remove bubbletea

* Cleanup readwriter

* Use embedded templates instead of serving over API

* Move templates to examples

* Improve workspace create flow

* Fix Windows build

* Fix tests

* Fix linting errors

* Fix untar with extracting max size

* Fix newline char
2022-03-22 13:17:50 -06:00
Kyle Carberry bf0ae8f573 feat: Refactor API routes to use UUIDs instead of friendly names (#401)
* Add client for agent

* Cleanup code

* Fix linting error

* Rename routes to be simpler

* Rename workspace history to workspace build

* Refactor HTTP middlewares to use UUIDs

* Cleanup routes

* Compiles!

* Fix files and organizations

* Fix querying

* Fix agent lock

* Cleanup database abstraction

* Add parameters

* Fix linting errors

* Fix log race

* Lock on close wait

* Fix log cleanup

* Fix e2e tests

* Fix upstream version of opencensus-go

* Update coderdtest.go

* Fix coverpkg

* Fix codecov ignore
2022-03-07 11:40:54 -06:00