Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91c5b76

Browse files
bpmctnickvigilante
andauthored
docs(provider/env): clarify merge_strategy does not include host environment (#538)
* docs(provider/env): clarify merge_strategy does not include host environment * Nick's code review --------- Co-authored-by: Nick Vigilante <[email protected]>
1 parent b6ff7a2 commit 91c5b76

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

docs/resources/env.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ resource "coder_env" "internal_api_url" {
3232
name = "INTERNAL_API_URL"
3333
value = "https://api.internal.company.com/v1"
3434
}
35+
36+
# Append to PATH without losing the directories already set by the
37+
# workspace's image. Only one coder_env resource needs to reference
38+
# $PATH; the others can append plain values.
39+
resource "coder_env" "path_cuda" {
40+
agent_id = coder_agent.dev.id
41+
name = "PATH"
42+
value = "$PATH:/usr/local/cuda/bin"
43+
merge_strategy = "append"
44+
}
45+
46+
resource "coder_env" "path_go" {
47+
agent_id = coder_agent.dev.id
48+
name = "PATH"
49+
value = "/usr/local/go/bin"
50+
merge_strategy = "append"
51+
}
3552
```
3653

3754
<!-- schema generated by tfplugindocs -->
@@ -44,7 +61,14 @@ resource "coder_env" "internal_api_url" {
4461

4562
### Optional
4663

47-
- `merge_strategy` (String) Controls how this environment variable is merged when multiple coder_env resources define the same name. `replace` (default): last value wins. `append`: appends to existing value with a colon `:` separator. `prepend`: prepends to existing value with a colon `:` separator. `error`: fail the build if another coder_env defines the same name. When multiple resources append or prepend to the same name, they are applied in alphabetical order by Terraform resource address.
64+
- `merge_strategy` (String) Controls how this environment variable is merged when multiple coder_env resources define the same name.
65+
When multiple resources append or prepend to the same name, they are applied in alphabetical order by Terraform resource address.
66+
This only merges values across `coder_env` resources; it does not consider any value already present in the workspace's environment, such as a base image's `PATH`.
67+
To extend such a value, reference it directly (e.g., `value = "$PATH:/usr/local/bin"`), so the agent expands it against the real environment at startup. Valid values are as follows:
68+
- `replace` (default): last value wins.
69+
- `append`: appends to existing value with a colon `:` separator.
70+
- `prepend`: prepends to existing value with a colon `:` separator.
71+
- `error`: fail the build if another coder_env defines the same name.
4872
- `value` (String) The value of the environment variable.
4973

5074
### Read-Only

examples/resources/coder_env/resource.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,21 @@ resource "coder_env" "internal_api_url" {
1616
agent_id = coder_agent.dev.id
1717
name = "INTERNAL_API_URL"
1818
value = "https://api.internal.company.com/v1"
19-
}
19+
}
20+
21+
# Append to PATH without losing the directories already set by the
22+
# workspace's image. Only one coder_env resource needs to reference
23+
# $PATH; the others can append plain values.
24+
resource "coder_env" "path_cuda" {
25+
agent_id = coder_agent.dev.id
26+
name = "PATH"
27+
value = "$PATH:/usr/local/cuda/bin"
28+
merge_strategy = "append"
29+
}
30+
31+
resource "coder_env" "path_go" {
32+
agent_id = coder_agent.dev.id
33+
name = "PATH"
34+
value = "/usr/local/go/bin"
35+
merge_strategy = "append"
36+
}

provider/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func envResource() *schema.Resource {
4747
},
4848
"merge_strategy": {
4949
Type: schema.TypeString,
50-
Description: "Controls how this environment variable is merged when multiple coder_env resources define the same name. `replace` (default): last value wins. `append`: appends to existing value with a colon `:` separator. `prepend`: prepends to existing value with a colon `:` separator. `error`: fail the build if another coder_env defines the same name. When multiple resources append or prepend to the same name, they are applied in alphabetical order by Terraform resource address.",
50+
Description: "Controls how this environment variable is merged when multiple coder_env resources define the same name.\nWhen multiple resources append or prepend to the same name, they are applied in alphabetical order by Terraform resource address.\nThis only merges values across `coder_env` resources; it does not consider any value already present in the workspace's environment, such as a base image's `PATH`.\nTo extend such a value, reference it directly (e.g., `value = \"$PATH:/usr/local/bin\"`), so the agent expands it against the real environment at startup. Valid values are as follows:\n - `replace` (default): last value wins.\n - `append`: appends to existing value with a colon `:` separator.\n - `prepend`: prepends to existing value with a colon `:` separator.\n - `error`: fail the build if another coder_env defines the same name.",
5151
ForceNew: true,
5252
Optional: true,
5353
Default: "replace",

0 commit comments

Comments
 (0)