Skip to content

Commit 29dbfe0

Browse files
authored
docs: parameters (#6332)
* docs: parameters * mention legacy parameters
1 parent 677721e commit 29dbfe0

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

docs/images/parameters.png

423 KB
Loading

docs/templates.md

+42-24
Original file line numberDiff line numberDiff line change
@@ -187,39 +187,57 @@ coder dotfiles -y ${var.dotfiles_uri}
187187

188188
### Parameters
189189

190-
Templates often contain _parameters_. These are defined by `variable` blocks in
191-
Terraform. There are two types of parameters:
190+
Templates can contain _parameters_, which prompt the user for additional information
191+
in the "create workspace" screen.
192192

193-
- **Admin/template-wide parameters** are set when a template is created/updated.
194-
These values are often cloud configuration, such as a `VPC`, and are annotated
195-
with `sensitive = true` in the template code.
196-
- **User/workspace parameters** are set when a user creates a workspace. These
197-
values are often personalization settings such as "preferred region", "machine
198-
type" or "workspace image".
199-
200-
The template sample below uses _admin and user parameters_ to allow developers
201-
to create workspaces from any image as long as it is in the proper registry:
193+
![Parameters in Create Workspace screen](./images/parameters.png)
202194

203195
```hcl
204-
variable "image_registry_url" {
205-
description = "The image registry developers can select"
206-
default = "artifactory1.organization.com"
207-
sensitive = true # admin (template-wide) parameter
208-
}
196+
data "coder_parameter" "docker_host" {
197+
name = "Region"
198+
description = "Which region would you like to deploy to?"
199+
icon = "/emojis/1f30f.png"
200+
type = "string"
201+
default = "tcp://100.94.74.63:2375"
202+
203+
option {
204+
name = "Pittsburgh, USA"
205+
value = "tcp://100.94.74.63:2375"
206+
icon = "/emojis/1f1fa-1f1f8.png"
207+
}
209208
210-
variable "docker_image_name" {
211-
description = "The image your workspace will start from"
212-
default = "base_image"
213-
sensitive = false # user (workspace) parameter
209+
option {
210+
name = "Helsinki, Finland"
211+
value = "tcp://100.117.102.81:2375"
212+
icon = "/emojis/1f1eb-1f1ee.png"
213+
}
214+
215+
option {
216+
name = "Sydney, Australia"
217+
value = "tcp://100.127.2.1:2375"
218+
icon = "/emojis/1f1e6-1f1f9.png"
219+
}
214220
}
221+
```
215222

216-
resource "docker_image" "workspace" {
217-
# ... other config
218-
name = "${var.image_registry_url}/${var.docker_image_name}"
223+
From there, parameters can be referenced during build-time:
224+
225+
```hcl
226+
provider "docker" {
227+
host = data.coder_parameter.docker_host.value
219228
}
220229
```
221230

222-
#### Start/stop
231+
> For a complete list of supported parameter types, see the
232+
> [coder_parameter Terraform reference](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/parameter)
233+
234+
#### Legacy parameters (deprecated)
235+
236+
Prior to Coder v0.16.0 (Jan 2023), parameters were defined via Terraform `variable` blocks. These "legacy parameters" can still be used in templates, but are deprecated and will be removed in April 2023.
237+
238+
> ⚠️ Legacy (`variable`) parameters and rich parameters cannot be used in the same template.
239+
240+
### Start/stop
223241

224242
[Learn about resource persistence in Coder](./templates/resource-persistence.md)
225243

0 commit comments

Comments
 (0)