Skip to content

Commit e550365

Browse files
authored
chore(docs): update documentation for coder_workspace_tags (coder#15620)
Adds documentation relating to coder#15087 and coder#15427 See also: coder#15578
1 parent 0896f33 commit e550365

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

docs/admin/templates/extending-templates/workspace-tags.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,33 @@ Review the
4040
[full template example](https://github.com/coder/coder/tree/main/examples/workspace-tags)
4141
using `coder_workspace_tags` and `coder_parameter`s.
4242

43+
## How it Works
44+
45+
In order to correctly import a template that defines tags in
46+
`coder_workspace_tags`, Coder needs to know the tags to assign the template
47+
import job ahead of time. To work around this chicken-and-egg problem, Coder
48+
performs static analysis of the Terraform to determine a reasonable set of tags
49+
to assign to the template import job. This happens _before_ the job is started.
50+
51+
When the template is imported, Coder will then store the _raw_ Terraform
52+
expressions for the values of the workspace tags for that template version. The
53+
next time a workspace is created from that template, Coder retrieves the stored
54+
raw values from the database and evaluates them using provided template
55+
variables and parameters. This is illustrated in the table below:
56+
57+
| Value Type | Template Import | Workspace Creation |
58+
| ---------- | -------------------------------------------------- | ----------------------- |
59+
| Static | `{"region": "us"}` | `{"region": "us"}` |
60+
| Variable | `{"az": var.az}` | `{"region": "us-east"}` |
61+
| Parameter | `{"cluster": data.coder_parameter.cluster.value }` | `{"cluster": "dev"}` |
62+
4363
## Constraints
4464

65+
### Default Values
66+
67+
All template variables and `coder_parameter` data sources **must** provide a
68+
default value. Failure to do so will result in an error.
69+
4570
### Tagged provisioners
4671

4772
It is possible to choose tag combinations that no provisioner can handle. This
@@ -70,15 +95,15 @@ the workspace owner to change a provisioner group (due to different tags). In
7095
most cases, `coder_parameter`s backing `coder_workspace_tags` should be marked
7196
as immutable and set only once, during workspace creation.
7297

73-
We recommend using only the following as inputs for `coder_workspace_tags`:
98+
You may only specify the following as inputs for `coder_workspace_tags`:
7499

75100
| | Example |
76101
| :----------------- | :-------------------------------------------- |
77102
| Static values | `"developers"` |
78103
| Template variables | `var.az` |
79104
| Coder parameters | `data.coder_parameter.runtime_selector.value` |
80105

81-
Passing template tags in from other data sources may have undesired effects.
106+
Passing template tags in from other data sources or resources is not permitted.
82107

83108
### HCL syntax
84109

@@ -99,3 +124,9 @@ variables, and references to other resources.
99124
- Boolean logic: `production_tag = !data.coder_parameter.staging_env.value`
100125
- Condition:
101126
`cache = data.coder_parameter.feature_cache_enabled.value == "true" ? "with-cache" : "no-cache"`
127+
128+
**Not supported**
129+
130+
- Function calls: `try(var.foo, "default")`
131+
- Resources: `compute_instance.dev.name`
132+
- Data sources other than `coder_parameter`: `data.local_file.hostname.content`

examples/workspace-tags/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ Template administrators can use static tags to control workspace provisioning, l
1515

1616
By using `coder_workspace_tags` and `coder_parameter`s, template administrators can allow dynamic tag selection, avoiding the need to push the same template multiple times with different tags.
1717

18+
# Notes
19+
20+
- You will need to have an [external provisioner](https://coder.com/docs/admin/provisioners#external-provisioners) with the correct tagset running in order to import this template.
21+
- When specifying values for the `coder_workspace_tags` data source, you are restricted to using a subset of Terraform's capabilities.
22+
- You must specify default values for all data sources and variables referenced by the `coder_workspace_tags` data source.
23+
24+
See [Workspace Tags](https://coder.com/docs/templates/workspace-tags) for more information.
25+
1826
## Development
1927

2028
Update the template and push it using the following command:

examples/workspace-tags/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ data "coder_parameter" "project_name" {
5454
name = "project_name"
5555
display_name = "Project name"
5656
description = "Specify the project name."
57-
58-
mutable = false
57+
default = "SUPERSECRET"
58+
mutable = false
5959
}
6060

6161
data "coder_parameter" "feature_cache_enabled" {

0 commit comments

Comments
 (0)