Skip to content

chore: keep previous workspace build parameters for dynamic params #18059

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 8 commits into from
May 28, 2025
Merged
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
Next Next commit
chore: keep previous workspace build parameters for dynamic params
  • Loading branch information
Emyrk committed May 27, 2025
commit 68fb74860f9f5747a81c5301f781f0bd147be38f
27 changes: 23 additions & 4 deletions coderd/wsbuilder/wsbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -632,19 +637,33 @@ 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)
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 {
continue
}
names = append(names, last.Name)
values = append(values, last.Value)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I am skipping validation right now for dynamic params experimental. I have an issue to address this again later.

#17942

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 {
Expand Down