Skip to content

feat: Add CLI support for workspace build parameters #5768

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 16 commits into from
Jan 23, 2023
Prev Previous commit
Next Next commit
CLI: is mutable
  • Loading branch information
mtojek committed Jan 19, 2023
commit a78f798b9c542ea2176a8076f7b60192612ae411
1 change: 0 additions & 1 deletion cli/cliui/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func RichParameter(cmd *cobra.Command, templateVersionParameter codersdk.Templat
}

// TODO Implement full validation and show descriptions.
// TODO Is mutable?
var err error
var value string
if len(templateVersionParameter.Options) > 0 {
Expand Down
11 changes: 9 additions & 2 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ type prepWorkspaceBuildArgs struct {
ExistingRichParams []codersdk.WorkspaceBuildParameter
RichParameterFile string
NewWorkspaceName string

UpdateWorkspace bool
}

type buildParameters struct {
Expand Down Expand Up @@ -261,7 +263,7 @@ PromptParamLoop:
if args.ParameterFile != "" {
useParamFile = true
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Paragraph.Render("Attempting to read the variables from the rich parameter file.")+"\r\n")
parameterMapFromFile, err = createParameterMapFromFile(args.ParameterFile)
parameterMapFromFile, err = createParameterMapFromFile(args.RichParameterFile)
if err != nil {
return nil, err
}
Expand All @@ -277,7 +279,7 @@ PromptRichParamLoop:

// Param file is all or nothing
if !useParamFile {
for _, e := range args.ExistingParams {
for _, e := range args.ExistingRichParams {
if e.Name == templateVersionParameter.Name {
// If the param already exists, we do not need to prompt it again.
// The workspace scope will reuse params for each build.
Expand All @@ -286,6 +288,11 @@ PromptRichParamLoop:
}
}

if args.UpdateWorkspace && !templateVersionParameter.Mutable {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Warn.Render(fmt.Sprintf(`Parameter %q is not mutable, so can't be customized after workspace creation.`, templateVersionParameter.Name)))
continue
}

parameterValue, err := getWorkspaceBuildParameterValueFromMapOrInput(cmd, parameterMapFromFile, templateVersionParameter)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func update() *cobra.Command {
ExistingRichParams: existingRichParams,
RichParameterFile: richParameterFile,
NewWorkspaceName: workspace.Name,
UpdateWorkspace: true,
})
if err != nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions coderd/workspacebuilds.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
}

if parameters == nil {
// TODO Is mutable?
buildParameters, err := api.Database.GetWorkspaceBuildParameters(ctx, priorHistory.ID)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Expand Down