Kacper Sawicki
1e07ec49a6
feat: add merge_strategy support for coder_env resources ( #23107 )
...
## Description
Implements the server-side merge logic for the `merge_strategy`
attribute added to `coder_env` in [terraform-provider-coder
v2.15.0](https://github.com/coder/terraform-provider-coder/pull/489 ).
This allows template authors to control how duplicate environment
variable names are combined across multiple `coder_env` resources.
Relates to https://github.com/coder/coder/issues/21885
## Supported strategies
| Strategy | Behavior |
|----------|----------|
| `replace` (default) | Last value wins — backward compatible |
| `append` | Joins values with `:` separator (e.g. PATH additions) |
| `prepend` | Prepends value with `:` separator |
| `error` | Fails the build if the variable is already defined |
## Example
```hcl
resource "coder_env" "path_tools" {
agent_id = coder_agent.dev.id
name = "PATH"
value = "/home/coder/tools/bin"
merge_strategy = "append"
}
```
## Changes
- **Proto**: Added `merge_strategy` field to `Env` message in
`provisioner.proto`
- **State reader**: Updated `agentEnvAttributes` struct and proto
construction in `resources.go`
- **Merge logic**: Added `mergeExtraEnvs()` function in
`provisionerdserver.go` with strategy-aware merging for both agent envs
and devcontainer subagent envs
- **Tests**: 15 unit tests covering all strategies, edge cases (empty
values, mixed strategies, multiple appends)
- **Dependency**: Bumped `terraform-provider-coder` v2.14.0 → v2.15.0
- **Fixtures**: Updated `duplicate-env-keys` test fixtures and golden
files
## Ordering
When multiple resources `append` or `prepend` to the same key, they are
processed in alphabetical order by Terraform resource address (per the
determinism fix in #22706 ).
2026-03-18 15:43:28 +01:00
..
2026-01-08 15:24:11 +04:00
2026-03-12 08:33:09 -06:00
2026-03-05 09:35:57 -08:00
2025-06-24 11:16:31 +02:00
2024-02-26 10:03:49 -06:00
2026-01-08 15:24:11 +04:00
2026-03-12 13:39:24 -06:00
2026-03-11 15:19:56 +02:00
2023-09-04 21:42:45 +03:00
2026-03-18 15:43:28 +01:00
2025-06-20 13:16:55 -06:00
2026-03-03 21:23:59 +04:00
2026-03-03 21:23:59 +04:00
2025-10-27 17:07:25 +01:00
2025-06-20 13:16:55 -06:00
2025-09-22 17:14:07 +04:00
2024-08-22 15:40:53 +10:00
2025-09-29 17:01:54 +04:00
2025-06-06 16:44:25 +04:00
2025-07-03 11:28:00 -06:00
2025-06-06 16:44:25 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-03-16 11:54:30 -06:00
2026-03-16 11:54:30 -06:00
2026-01-08 15:24:11 +04:00
2025-09-22 17:14:07 +04:00
2025-03-04 15:37:29 -07:00
2025-03-04 15:37:29 -07:00
2025-03-04 15:37:29 -07:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-03-26 01:56:39 -05:00
2026-03-18 10:21:45 +00:00
2026-03-18 10:21:45 +00:00
2026-03-05 09:35:57 -08:00
2026-01-08 15:24:11 +04:00
2025-09-22 17:14:07 +04:00
2026-02-02 16:16:16 +02:00
2026-01-08 15:24:11 +04:00
2026-03-10 12:08:40 +02:00
2026-01-08 15:24:11 +04:00
2026-02-25 11:16:20 -06:00
2024-03-17 09:45:26 -05:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-03-13 20:37:41 -07:00
2025-03-26 01:56:39 -05:00
2025-09-03 10:49:19 +04:00
2026-01-08 15:24:11 +04:00
2025-09-22 17:14:07 +04:00
2025-09-03 10:38:42 +04:00
2026-03-02 22:52:39 -05:00
2026-03-10 12:12:15 +02:00
2025-09-03 10:49:19 +04:00
2025-03-26 01:56:39 -05:00
2023-09-08 18:21:33 +00:00
2025-12-15 09:40:59 -07:00
2026-02-23 08:30:32 -08:00
2025-12-03 11:32:59 +02:00
2026-03-10 15:40:54 +02:00
2026-03-10 15:40:54 +02:00
2025-05-12 11:45:24 -07:00
2025-10-30 17:41:08 -06:00
2026-01-08 15:24:11 +04:00
2026-02-03 09:45:23 +00:00
2024-06-13 10:19:36 +04:00
2025-09-22 17:14:07 +04:00
2025-09-11 15:08:57 +02:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-12-22 11:28:31 +00:00
2026-01-07 16:06:00 +00:00
2026-02-06 14:09:39 +11:00
2026-02-06 14:09:39 +11:00
2026-02-05 19:35:20 +11:00
2026-02-06 14:09:39 +11:00
2025-09-22 17:14:07 +04:00
2024-08-20 14:47:46 +10:00
2025-12-03 11:32:59 +02:00
2024-05-23 07:54:59 -10:00
2026-03-17 12:16:43 -07:00
2026-03-04 11:14:52 -07:00
2023-08-09 13:00:25 +02:00
2025-07-28 14:46:04 +01:00
2026-02-26 14:34:30 +01:00
2026-02-26 14:34:30 +01:00
2025-07-03 13:22:54 +10:00
2025-02-24 05:38:17 +00:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-06-27 14:42:22 +04:00
2026-01-08 15:24:11 +04:00
2025-10-06 08:56:43 +00:00
2025-12-03 11:32:59 +02:00
2026-03-03 08:47:34 +00:00
2025-12-03 11:32:59 +02:00
2023-08-18 18:55:43 +00:00
2026-01-08 15:24:11 +04:00
2025-03-26 01:56:39 -05:00
2024-07-30 10:44:02 -06:00
2026-01-08 15:24:11 +04:00
2024-03-17 09:45:26 -05:00
2024-11-04 17:23:31 +01:00
2026-01-08 15:24:11 +04:00
2025-12-15 11:26:41 -06:00
2025-09-22 17:14:07 +04:00
2025-06-20 13:16:55 -06:00
2026-01-12 17:46:05 +00:00
2026-03-12 08:33:09 -06:00
2025-06-20 13:16:55 -06:00
2025-10-24 10:18:19 +00:00
2025-12-03 11:32:59 +02:00
2024-11-04 17:23:31 +01:00
2026-03-11 10:19:08 -07:00
2026-03-04 20:26:03 -05:00
2025-10-23 14:24:54 +02:00
2026-01-08 15:24:11 +04:00
2024-03-17 09:45:26 -05:00
2026-03-10 18:46:01 +00:00
2026-03-10 18:46:01 +00:00
2026-02-23 08:30:32 -08:00
2026-01-08 15:24:11 +04:00
2026-01-16 15:45:33 +00:00
2026-01-16 15:45:33 +00:00
2024-03-15 13:16:36 +00:00
2024-03-15 13:16:36 +00:00
2024-11-18 14:09:22 +04:00
2026-01-08 15:24:11 +04:00
2026-02-09 09:56:33 +00:00
2023-07-20 12:05:39 +02:00
2026-03-12 18:07:52 +02:00
2023-07-20 12:05:39 +02:00
2026-03-10 12:08:40 +02:00
2026-01-30 13:24:06 +11:00
2026-02-24 19:51:48 -05:00
2025-03-26 10:36:53 +00:00
2025-03-26 10:36:53 +00:00
2026-02-23 22:46:17 -06:00
2026-01-12 15:16:59 +01:00
2025-09-22 17:14:07 +04:00
2026-03-18 13:43:10 +00:00
2026-03-18 13:43:10 +00:00
2025-11-28 08:33:50 +02:00
2025-11-28 08:33:50 +02:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-03-12 18:07:52 +02:00
2026-01-08 15:24:11 +04:00
2025-11-28 08:33:50 +02:00
2025-11-25 15:24:25 +00:00
2025-11-25 15:24:25 +00:00
2025-11-25 15:24:25 +00:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2025-12-03 11:32:59 +02:00
2026-03-07 01:36:03 +00:00
2026-02-02 15:50:09 +02:00
2026-03-07 01:36:03 +00:00
2026-02-13 14:21:31 +00:00
2026-03-07 01:36:03 +00:00
2026-02-17 16:24:13 +00:00
2026-03-07 01:36:03 +00:00
2026-03-07 01:36:03 +00:00
2026-03-12 08:33:09 -06:00
2026-03-12 08:33:09 -06:00
2026-03-07 01:36:03 +00:00
2026-02-17 16:24:13 +00:00
2024-07-25 16:07:53 -05:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2026-01-08 15:24:11 +04:00
2023-08-18 18:55:43 +00:00
2024-03-17 09:45:26 -05:00
2024-07-25 16:07:53 -05:00
2025-12-03 11:32:59 +02:00
2025-12-15 11:26:41 -06:00
2025-12-03 11:32:59 +02:00
2025-06-20 13:16:55 -06:00
2025-09-22 17:14:07 +04:00
2025-12-15 11:26:41 -06:00
2025-10-03 10:20:06 -05:00
2025-07-24 16:44:36 +01:00
2025-12-15 11:26:41 -06:00
2025-09-22 17:14:07 +04:00
2026-02-19 09:31:12 +11:00
2026-02-19 09:31:12 +11:00
2026-03-06 00:04:09 +00:00
2026-02-24 15:27:03 +00:00
2026-02-24 09:15:02 +01:00
2025-09-22 17:14:07 +04:00
2024-08-23 21:23:51 +00:00
2026-03-17 14:07:20 -08:00
2026-03-17 14:07:20 -08:00
2025-09-22 17:14:07 +04:00
2025-04-15 18:30:20 -04:00
2025-09-22 17:14:07 +04:00
2025-05-12 11:45:24 -07:00
2025-12-03 11:32:59 +02:00
2025-04-15 18:30:20 -04:00
2023-10-10 11:14:20 +01:00
2026-01-08 15:24:11 +04:00
2025-06-20 13:16:55 -06:00
2025-03-26 01:56:39 -05:00
2025-06-20 13:16:55 -06:00
2026-01-08 15:24:11 +04:00
2026-01-08 15:24:11 +04:00
2026-02-12 12:14:56 +01:00
2026-02-12 12:14:56 +01:00
2026-02-12 12:14:56 +01:00
2026-02-12 12:14:56 +01:00
2024-11-18 21:10:01 +10:00
2024-11-18 14:09:22 +04:00
2026-01-08 15:24:11 +04:00
2024-07-09 13:23:11 -05:00
2025-09-26 11:20:25 +01:00