Skip to content

Commit bd5666a

Browse files
cstyanrowansmithau
andauthored
feat: cli: add support for supplying ephemeral parameters at workspac… (#26280)
cherry pick #26012 into release 2.34 Co-authored-by: Rowan Smith <rowan@coder.com>
1 parent 05e50d1 commit bd5666a

6 files changed

Lines changed: 140 additions & 5 deletions

File tree

cli/create.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
271271
return xerrors.Errorf("can't parse given parameter defaults: %w", err)
272272
}
273273

274+
cliEphemeralParameters, err := asWorkspaceBuildParameters(parameterFlags.ephemeralParameters)
275+
if err != nil {
276+
return xerrors.Errorf("can't parse given ephemeral parameter values: %w", err)
277+
}
278+
274279
var sourceWorkspaceParameters []codersdk.WorkspaceBuildParameter
275280
if copyParametersFrom != "" {
276281
sourceWorkspaceParameters, err = client.WorkspaceBuildParameters(inv.Context(), sourceWorkspace.LatestBuild.ID)
@@ -330,6 +335,9 @@ func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
330335
RichParameters: cliBuildParameters,
331336
RichParameterDefaults: cliBuildParameterDefaults,
332337

338+
PromptEphemeralParameters: parameterFlags.promptEphemeralParameters,
339+
EphemeralParameters: cliEphemeralParameters,
340+
333341
SourceWorkspaceParameters: sourceWorkspaceParameters,
334342

335343
UseParameterDefaults: parameterFlags.useParameterDefaults,
@@ -455,9 +463,8 @@ func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
455463
},
456464
cliui.SkipPromptOption(),
457465
)
458-
cmd.Options = append(cmd.Options, parameterFlags.cliParameters()...)
459-
cmd.Options = append(cmd.Options, parameterFlags.cliParameterDefaults()...)
460-
cmd.Options = append(cmd.Options, parameterFlags.useParameterDefaultsOption())
466+
cmd.Options = append(cmd.Options, parameterFlags.allOptions()...)
467+
461468
orgContext.AttachOptions(cmd)
462469
return cmd
463470
}

cli/testdata/coder_create_--help.golden

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,29 @@ OPTIONS:
1313
-O, --org string, $CODER_ORGANIZATION
1414
Select which organization (uuid or name) to use.
1515

16+
--always-prompt bool
17+
Always prompt all parameters. Does not pull parameter values from
18+
existing workspace.
19+
1620
--automatic-updates string, $CODER_WORKSPACE_AUTOMATIC_UPDATES (default: never)
1721
Specify automatic updates setting for the workspace (accepts 'always'
1822
or 'never').
1923

24+
--build-option string-array, $CODER_BUILD_OPTION
25+
Build option value in the format "name=value".
26+
DEPRECATED: Use --ephemeral-parameter instead.
27+
28+
--build-options bool
29+
Prompt for one-time build options defined with ephemeral parameters.
30+
DEPRECATED: Use --prompt-ephemeral-parameters instead.
31+
2032
--copy-parameters-from string, $CODER_WORKSPACE_COPY_PARAMETERS_FROM
2133
Specify the source workspace name to copy parameters from.
2234

35+
--ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER
36+
Set the value of ephemeral parameters defined in the template. The
37+
format is "name=value".
38+
2339
--no-wait bool, $CODER_CREATE_NO_WAIT
2440
Return immediately after creating the workspace. The build will run in
2541
the background.
@@ -34,6 +50,11 @@ OPTIONS:
3450
Specify the name of a template version preset. Use 'none' to
3551
explicitly indicate that no preset should be used.
3652

53+
--prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS
54+
Prompt to set values of ephemeral parameters defined in the template.
55+
If a value has been set via --ephemeral-parameter, it will not be
56+
prompted for.
57+
3758
--rich-parameter-file string, $CODER_RICH_PARAMETER_FILE
3859
Specify a file path with values for rich parameters defined in the
3960
template. The file should be in YAML format, containing key-value

docs/admin/templates/extending-templates/parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ parameters, the **Create workspace** button is disabled until the issues are res
232232
Ephemeral parameters are introduced to users in order to model specific
233233
behaviors in a Coder workspace, such as reverting to a previous image, restoring
234234
from a volume snapshot, or building a project without using cache. These
235-
parameters are only settable when starting, updating, or restarting a workspace
236-
and do not persist after the workspace is stopped.
235+
parameters are settable when creating, starting, updating, or restarting a workspace
236+
but do not persist after the workspace is stopped.
237237
238238
Since these parameters are ephemeral in nature, subsequent builds proceed in the
239239
standard manner:

docs/reference/cli/create.md

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/cli/external-workspaces_create.md

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/cli/testdata/coder_external-workspaces_create_--help.golden

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,29 @@ OPTIONS:
1313
-O, --org string, $CODER_ORGANIZATION
1414
Select which organization (uuid or name) to use.
1515

16+
--always-prompt bool
17+
Always prompt all parameters. Does not pull parameter values from
18+
existing workspace.
19+
1620
--automatic-updates string, $CODER_WORKSPACE_AUTOMATIC_UPDATES (default: never)
1721
Specify automatic updates setting for the workspace (accepts 'always'
1822
or 'never').
1923

24+
--build-option string-array, $CODER_BUILD_OPTION
25+
Build option value in the format "name=value".
26+
DEPRECATED: Use --ephemeral-parameter instead.
27+
28+
--build-options bool
29+
Prompt for one-time build options defined with ephemeral parameters.
30+
DEPRECATED: Use --prompt-ephemeral-parameters instead.
31+
2032
--copy-parameters-from string, $CODER_WORKSPACE_COPY_PARAMETERS_FROM
2133
Specify the source workspace name to copy parameters from.
2234

35+
--ephemeral-parameter string-array, $CODER_EPHEMERAL_PARAMETER
36+
Set the value of ephemeral parameters defined in the template. The
37+
format is "name=value".
38+
2339
--no-wait bool, $CODER_CREATE_NO_WAIT
2440
Return immediately after creating the workspace. The build will run in
2541
the background.
@@ -34,6 +50,11 @@ OPTIONS:
3450
Specify the name of a template version preset. Use 'none' to
3551
explicitly indicate that no preset should be used.
3652

53+
--prompt-ephemeral-parameters bool, $CODER_PROMPT_EPHEMERAL_PARAMETERS
54+
Prompt to set values of ephemeral parameters defined in the template.
55+
If a value has been set via --ephemeral-parameter, it will not be
56+
prompted for.
57+
3758
--rich-parameter-file string, $CODER_RICH_PARAMETER_FILE
3859
Specify a file path with values for rich parameters defined in the
3960
template. The file should be in YAML format, containing key-value

0 commit comments

Comments
 (0)