fix: honor parameter defaults in --use-parameter-defaults and SSH auto-start by jeremyruppel · Pull Request #24591 · coder/coder · GitHub
Skip to content

fix: honor parameter defaults in --use-parameter-defaults and SSH auto-start#24591

Merged
jeremyruppel merged 5 commits intomainfrom
fix/cli-honor-parameter-defaults
Apr 24, 2026
Merged

fix: honor parameter defaults in --use-parameter-defaults and SSH auto-start#24591
jeremyruppel merged 5 commits intomainfrom
fix/cli-honor-parameter-defaults

Conversation

@jeremyruppel
Copy link
Copy Markdown
Contributor

@jeremyruppel jeremyruppel commented Apr 21, 2026

Problem

The CLI does not honor default values on template parameters in two ways:

  1. --use-parameter-defaults rejects empty-string defaults. The check parameterValue != "" means default = "" in Terraform falls through to an interactive prompt. In CI this causes an EOF error.

  2. --use-parameter-defaults only exists on coder create. The start, update, and restart commands never wire it through. SSH auto-start passes empty workspaceParameterFlags{}, so users SSH-ing into a stopped workspace with new template parameters get stuck in an interactive prompt they cannot complete.

Fix

1. Fix empty-string default detection and expose flag on all commands

Replace parameterValue != "" with a check based on !tvp.Required. A parameter with Required==false always has a valid default in Terraform, even if that default is "". Also respect CLI defaults provided via --parameter-default.

Move --use-parameter-defaults from a standalone option on create into the shared workspaceParameterFlags struct. This exposes the flag (and CODER_WORKSPACE_USE_PARAMETER_DEFAULTS) on start, update, and restart via allOptions(). Wire it through buildWorkspaceStartRequest so the resolver receives it.

2. SSH auto-start always uses defaults

Set useParameterDefaults: true on both startWorkspace calls in the SSH auto-start path (initial start and the forbidden/upgrade fallback). SSH is non-interactive and should never prompt.

Fixes https://linear.app/codercom/issue/DEVEX-180
Fixes #22272

Implementation notes

Scoping decisions

  • --yes does not imply --use-parameter-defaults: Making --yes auto-accept defaults exposes a validation gap in the dynamic parameter path (client-side validation happens during prompting, and skipping prompts bypasses it). This is deferred to a follow-up that also addresses codersdk.ValidateWorkspaceBuildParameter integration in the resolver. Tracked in PLAT-114.
  • Explicit overrides always win: --parameter, --rich-parameter-file, and --preset are resolved in stages 1-5 of the resolver, before resolveWithInput runs. No change needed for precedence.
  • !tvp.Required vs parameterValue != "": The Required field is set by the Terraform provider based on whether a default is present. This is the canonical signal for "has a default," not the string value itself.

Generated with Coder Agents

@jeremyruppel jeremyruppel added the community Pull Requests and issues created by the community. label Apr 21, 2026
@jeremyruppel jeremyruppel removed the community Pull Requests and issues created by the community. label Apr 21, 2026
@jeremyruppel jeremyruppel changed the title fix(cli): honor parameter defaults in --yes, --use-parameter-defaults, and SSH auto-start fix: honor parameter defaults in --yes, --use-parameter-defaults, and SSH auto-start Apr 21, 2026
@jeremyruppel jeremyruppel force-pushed the fix/cli-honor-parameter-defaults branch 2 times, most recently from 56f4427 to b6a1b10 Compare April 21, 2026 19:45
@jeremyruppel jeremyruppel changed the title fix: honor parameter defaults in --yes, --use-parameter-defaults, and SSH auto-start fix(cli): honor parameter defaults in --use-parameter-defaults and SSH auto-start Apr 21, 2026
@jeremyruppel jeremyruppel changed the title fix(cli): honor parameter defaults in --use-parameter-defaults and SSH auto-start fix: honor parameter defaults in --use-parameter-defaults and SSH auto-start Apr 21, 2026
@jeremyruppel jeremyruppel marked this pull request as ready for review April 21, 2026 20:26
@jeremyruppel jeremyruppel requested a review from code-asher April 21, 2026 20:26
@jeremyruppel jeremyruppel force-pushed the fix/cli-honor-parameter-defaults branch from b6a1b10 to c1b2cd7 Compare April 21, 2026 20:29
Copy link
Copy Markdown
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! It would be cool to add an empty string variable to the shared params in the create tests as well (and even better if we could add tests to the other commands as well) but otherwise looks good to me.

Comment thread cli/parameterresolver.go Outdated
@jeremyruppel jeremyruppel force-pushed the fix/cli-honor-parameter-defaults branch from b9ee383 to 779ac21 Compare April 24, 2026 14:05
…efaults

The auto-accept check used `parameterValue != ""` which rejected
parameters with `default = ""` in Terraform. A parameter with
Required==false always has a valid default, even if that default
is an empty string. Use !tvp.Required instead to determine whether
a usable default exists.
SSH is non-interactive, so when it auto-starts a stopped workspace
it should never prompt for parameter values. Set
useParameterDefaults=true on both the initial start and the
forbidden/upgrade fallback paths.
Verifies that --use-parameter-defaults accepts parameters with
default="" without prompting. Uses the classic parameter flow
because the echo provisioner sets Required via proto fields,
which the dynamic parameter evaluator does not read.
Verifies that the newly exposed --use-parameter-defaults flag
works on start and update commands. Both tests push a new template
version that adds a parameter with a default, then confirm the
command completes without prompting.
@jeremyruppel jeremyruppel force-pushed the fix/cli-honor-parameter-defaults branch from 779ac21 to 11e3d5d Compare April 24, 2026 15:13
@jeremyruppel jeremyruppel requested a review from code-asher April 24, 2026 15:38
@jeremyruppel
Copy link
Copy Markdown
Contributor Author

Copy link
Copy Markdown
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

Comment thread cli/create_test.go
Comment on lines +683 to +685
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make changes to make this work, I experimented with a poc here: 763f43a

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hell yeah!

@jeremyruppel jeremyruppel merged commit 02b1235 into main Apr 24, 2026
28 checks passed
@jeremyruppel jeremyruppel deleted the fix/cli-honor-parameter-defaults branch April 24, 2026 21:09
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: forced updates + new params (with defaults) blocks users starting workspace via ssh

2 participants