Files
coder/docs/reference/cli/create.md
T
Susana Ferreira b975d6d9b3 feat(cli): add CLI support for creating a workspace with preset (#18912)
## Description 

This PR introduces a `--preset` flag for the `create` command to allow
users to apply a predefined preset to their workspace build.

## Changes

- The `--preset` flag on the `create` command integrates with the
parameter resolution logic and takes precedence over other sources
(e.g., CLI/env vars, last build, etc.).
- Added internal logic to ensure that preset parameters override
parameters values during resolution.
- Updated tests and added new ones to cover these flows.

## Implementation logic

* If a template has presets and includes a default, the CLI will
automatically use the default when `--preset` is not specified.
* If a template has presets but no default, the CLI will prompt the user
to select one when `--preset` is not specified.
* If a template does not have presets, the CLI will not prompt the user
for a preset.
* If the user specifies a preset using the `--preset` flag, that preset
will be used.
* If the user passes `--preset None`, no preset will be applied.

This logic aligns with the behavior in the UI for consistency.

```
> coder create --help

USAGE:
  coder create [flags] [workspace]

  Create a workspace

    - Create a workspace for another user (if you have permission):

        $ coder create <username>/<workspace_name>

OPTIONS:
      (...)

      --preset string, $CODER_PRESET_NAME
          Specify the name of a template version preset. Use 'none' to explicitly indicate that no preset should be used.

      (...)

  -y, --yes bool
          Bypass prompts.
```

## Breaking change

**Note:** This is a breaking change to the create CLI command. If a
template includes presets and the user does not provide a `--preset`
flag, the CLI will now prompt the user to select one. This behavior may
break non-interactive scripts or automated workflows.


Relates to PR: https://github.com/coder/coder/pull/18910 - please
consider both PRs together as they’re part of the same workflow
Relates to issue: https://github.com/coder/coder/issues/16594
2025-07-28 14:46:04 +01:00

3.9 KiB
Generated

create

Create a workspace

Usage

coder create [flags] [workspace]

Description

  - Create a workspace for another user (if you have permission):

     $ coder create <username>/<workspace_name>

Options

-t, --template

Type string
Environment $CODER_TEMPLATE_NAME

Specify a template name.

--template-version

Type string
Environment $CODER_TEMPLATE_VERSION

Specify a template version name.

--preset

Type string
Environment $CODER_PRESET_NAME

Specify the name of a template version preset. Use 'none' to explicitly indicate that no preset should be used.

--start-at

Type string
Environment $CODER_WORKSPACE_START_AT

Specify the workspace autostart schedule. Check coder schedule start --help for the syntax.

--stop-after

Type duration
Environment $CODER_WORKSPACE_STOP_AFTER

Specify a duration after which the workspace should shut down (e.g. 8h).

--automatic-updates

Type string
Environment $CODER_WORKSPACE_AUTOMATIC_UPDATES
Default never

Specify automatic updates setting for the workspace (accepts 'always' or 'never').

--copy-parameters-from

Type string
Environment $CODER_WORKSPACE_COPY_PARAMETERS_FROM

Specify the source workspace name to copy parameters from.

-y, --yes

Type bool

Bypass prompts.

--parameter

Type string-array
Environment $CODER_RICH_PARAMETER

Rich parameter value in the format "name=value".

--rich-parameter-file

Type string
Environment $CODER_RICH_PARAMETER_FILE

Specify a file path with values for rich parameters defined in the template. The file should be in YAML format, containing key-value pairs for the parameters.

--parameter-default

Type string-array
Environment $CODER_RICH_PARAMETER_DEFAULT

Rich parameter default values in the format "name=value".

-O, --org

Type string
Environment $CODER_ORGANIZATION

Select which organization (uuid or name) to use.