From 0754ba11daaf6cbd3b5806b1675290f2d6270fcd Mon Sep 17 00:00:00 2001 From: Ben Potter Date: Mon, 24 Aug 2026 11:34:45 +0000 Subject: [PATCH 1/2] docs(provider/env): clarify merge_strategy does not include host environment --- docs/resources/env.md | 19 ++++++++++++++++++- examples/resources/coder_env/resource.tf | 19 ++++++++++++++++++- provider/env.go | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/docs/resources/env.md b/docs/resources/env.md index 860c5170..fd4ebb0c 100644 --- a/docs/resources/env.md +++ b/docs/resources/env.md @@ -32,6 +32,23 @@ resource "coder_env" "internal_api_url" { name = "INTERNAL_API_URL" value = "https://api.internal.company.com/v1" } + +# Append to PATH without losing the directories already set by the +# workspace's image. Only one coder_env resource needs to reference +# $PATH; the others can append plain values. +resource "coder_env" "path_cuda" { + agent_id = coder_agent.dev.id + name = "PATH" + value = "$PATH:/usr/local/cuda/bin" + merge_strategy = "append" +} + +resource "coder_env" "path_go" { + agent_id = coder_agent.dev.id + name = "PATH" + value = "/usr/local/go/bin" + merge_strategy = "append" +} ``` @@ -44,7 +61,7 @@ resource "coder_env" "internal_api_url" { ### Optional -- `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. +- `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. 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. 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. - `value` (String) The value of the environment variable. ### Read-Only diff --git a/examples/resources/coder_env/resource.tf b/examples/resources/coder_env/resource.tf index 9f8e28f2..3c966c9e 100644 --- a/examples/resources/coder_env/resource.tf +++ b/examples/resources/coder_env/resource.tf @@ -16,4 +16,21 @@ resource "coder_env" "internal_api_url" { agent_id = coder_agent.dev.id name = "INTERNAL_API_URL" value = "https://api.internal.company.com/v1" -} \ No newline at end of file +} + +# Append to PATH without losing the directories already set by the +# workspace's image. Only one coder_env resource needs to reference +# $PATH; the others can append plain values. +resource "coder_env" "path_cuda" { + agent_id = coder_agent.dev.id + name = "PATH" + value = "$PATH:/usr/local/cuda/bin" + merge_strategy = "append" +} + +resource "coder_env" "path_go" { + agent_id = coder_agent.dev.id + name = "PATH" + value = "/usr/local/go/bin" + merge_strategy = "append" +} diff --git a/provider/env.go b/provider/env.go index e00e7fa4..4407d8cc 100644 --- a/provider/env.go +++ b/provider/env.go @@ -47,7 +47,7 @@ func envResource() *schema.Resource { }, "merge_strategy": { Type: schema.TypeString, - 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.", + 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. 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. 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.", ForceNew: true, Optional: true, Default: "replace", From f2457ef3efc3f72a93c2c52805f9bb703f553a8f Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Mon, 24 Aug 2026 08:18:36 -0400 Subject: [PATCH 2/2] Nick's code review --- docs/resources/env.md | 9 ++++++++- provider/env.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/resources/env.md b/docs/resources/env.md index fd4ebb0c..b1e25867 100644 --- a/docs/resources/env.md +++ b/docs/resources/env.md @@ -61,7 +61,14 @@ resource "coder_env" "path_go" { ### Optional -- `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. 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. 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. +- `merge_strategy` (String) Controls how this environment variable is merged when multiple coder_env resources define the same name. +When multiple resources append or prepend to the same name, they are applied in alphabetical order by Terraform resource address. +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`. +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: + - `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. - `value` (String) The value of the environment variable. ### Read-Only diff --git a/provider/env.go b/provider/env.go index 4407d8cc..b277c72e 100644 --- a/provider/env.go +++ b/provider/env.go @@ -47,7 +47,7 @@ func envResource() *schema.Resource { }, "merge_strategy": { Type: schema.TypeString, - 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. 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. 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.", + 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.", ForceNew: true, Optional: true, Default: "replace",