mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
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.
This commit is contained in:
@@ -623,6 +623,11 @@ func (b *Builder) getParameters() (names, values []string, err error) {
|
||||
return nil, nil, BuildError{http.StatusBadRequest, "Unable to build workspace with unsupported parameters", err}
|
||||
}
|
||||
|
||||
lastBuildParameterValues := db2sdk.WorkspaceBuildParameters(lastBuildParameters)
|
||||
resolver := codersdk.ParameterResolver{
|
||||
Rich: lastBuildParameterValues,
|
||||
}
|
||||
|
||||
// Dynamic parameters skip all parameter validation.
|
||||
// Deleting a workspace also should skip parameter validation.
|
||||
// Pass the user's input as is.
|
||||
@@ -632,19 +637,34 @@ func (b *Builder) getParameters() (names, values []string, err error) {
|
||||
// conditional parameter existence, the static frame of reference
|
||||
// is not sufficient. So assume the user is correct, or pull in the
|
||||
// dynamic param code to find the actual parameters.
|
||||
latestValues := make(map[string]string, len(b.richParameterValues))
|
||||
for _, latest := range b.richParameterValues {
|
||||
latestValues[latest.Name] = latest.Value
|
||||
}
|
||||
|
||||
// Merge the inputs with values from the previous build.
|
||||
for _, last := range lastBuildParameterValues {
|
||||
// TODO: Ideally we use the resolver here and look at parameter
|
||||
// fields such as 'ephemeral'. This requires loading the terraform
|
||||
// files. For now, just send the previous inputs as is.
|
||||
if _, exists := latestValues[last.Name]; exists {
|
||||
// latestValues take priority, so skip this previous value.
|
||||
continue
|
||||
}
|
||||
names = append(names, last.Name)
|
||||
values = append(values, last.Value)
|
||||
}
|
||||
|
||||
for _, value := range b.richParameterValues {
|
||||
names = append(names, value.Name)
|
||||
values = append(values, value.Value)
|
||||
}
|
||||
|
||||
b.parameterNames = &names
|
||||
b.parameterValues = &values
|
||||
return names, values, nil
|
||||
}
|
||||
|
||||
resolver := codersdk.ParameterResolver{
|
||||
Rich: db2sdk.WorkspaceBuildParameters(lastBuildParameters),
|
||||
}
|
||||
|
||||
for _, templateVersionParameter := range templateVersionParameters {
|
||||
tvp, err := db2sdk.TemplateVersionParameter(templateVersionParameter)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user