Skip to content

chore: modify parameter dynamic immutability behavior #18583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
parameter values can change mutability
  • Loading branch information
Emyrk committed Jul 7, 2025
commit 02d07976f50e6e9ffb05ef1e919d6b3609928671
27 changes: 8 additions & 19 deletions coderd/dynamicparameters/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,6 @@ func ResolveParameters(
delete(values, parameter.Name)
}
}

// Immutable parameters should also not be allowed to be changed from
// the previous build. Remove any values taken from the preset or
// new build params. This forces the value to be the same as it was before.
//
// We do this so the next form render uses the original immutable value.
if !firstBuild && !parameter.Mutable {
delete(values, parameter.Name)
prev, ok := previousValuesMap[parameter.Name]
if ok {
values[parameter.Name] = parameterValue{
Value: prev,
Source: sourcePrevious,
}
}
}
}

// This is the final set of values that will be used. Any errors at this stage
Expand All @@ -118,19 +102,24 @@ func ResolveParameters(
return nil, parameterValidationError(diags)
}

// parameterNames is going to be used to remove any excess values that were left
// parameterNames is going to be used to remove any excess values left
// around without a parameter.
parameterNames := make(map[string]struct{}, len(output.Parameters))
parameterError := parameterValidationError(nil)
for _, parameter := range output.Parameters {
parameterNames[parameter.Name] = struct{}{}

if !firstBuild && !parameter.Mutable {
// previousValuesMap should be used over the first render output
// for the previous state of parameters. The previous build
// should emit all values, so the previousValuesMap should be
// complete with all parameter values (user specified and defaults)
originalValue, ok := previousValuesMap[parameter.Name]

// Immutable parameters should not be changed after the first build.
// If the value matches the original input value, that is fine.
// If the value matches the previous input value, that is fine.
//
// If the original value is not set, that means this is a new parameter. New
// If the previous value is not set, that means this is a new parameter. New
// immutable parameters are allowed. This is an opinionated choice to prevent
// workspaces failing to update or delete. Ideally we would block this, as
// immutable parameters should only be able to be set at creation time.
Expand Down
5 changes: 3 additions & 2 deletions coderd/dynamicparameters/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ func TestResolveParameters(t *testing.T) {
Parameters: []previewtypes.Parameter{
{
ParameterData: immutable,
Value: previewtypes.StringLiteral("foo"),
Diagnostics: nil,
// The user set the value to bar
Value: previewtypes.StringLiteral("bar"),
Diagnostics: nil,
},
},
}, nil)
Expand Down
Loading