mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(cli): allow new immutable parameters via --parameter flag during update (#22221)
## Problem When a template adds a new immutable parameter, `coder update --parameter param=value` fails with: ``` error: start workspace: parameter "machine_type" is immutable and cannot be updated ``` The interactive prompt handles this correctly (allows setting first-time immutable params), but the CLI `--parameter` flag path does not. ## Root Cause In `cli/parameterresolver.go`, `verifyConstraints()` runs before the interactive prompt and unconditionally rejects any immutable parameter during updates. It doesn't distinguish between **new** immutable parameters (first-time use, should be allowed) and **existing** ones (already set, should be blocked from changing). ## Fix Added an `isFirstTimeUse` check to the immutable parameter constraint, matching the logic already used by the interactive prompt path (line 323). New immutable parameters can now be set via `--parameter`, while existing immutable parameters are still blocked from being changed. ## Testing Added `TestUpdateValidateRichParameters/NewImmutableParameterViaFlag` which: 1. Creates a workspace with a mutable parameter 2. Updates the template to add a new immutable parameter 3. Runs `coder update --parameter immutable_param=value` 4. Verifies the update succeeds and the parameter is set correctly Fixes #22164
This commit is contained in:
@@ -297,7 +297,7 @@ func (pr *ParameterResolver) verifyConstraints(resolved []codersdk.WorkspaceBuil
|
||||
return xerrors.Errorf("ephemeral parameter %q can be used only with --prompt-ephemeral-parameters or --ephemeral-parameter flag", r.Name)
|
||||
}
|
||||
|
||||
if !tvp.Mutable && action != WorkspaceCreate {
|
||||
if !tvp.Mutable && action != WorkspaceCreate && !pr.isFirstTimeUse(r.Name) {
|
||||
return xerrors.Errorf("parameter %q is immutable and cannot be updated", r.Name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user