Skip to content

Commit 1c1842c

Browse files
author
Jay Kumar
committed
refactor(boundary): remove BOUNDARY_CONFIG env var, use output only
1 parent d1eb555 commit 1c1842c

4 files changed

Lines changed: 21 additions & 66 deletions

File tree

registry/coder/modules/boundary/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ This module:
1616
- Creates a wrapper script at `$HOME/.coder-modules/coder/boundary/scripts/boundary-wrapper.sh`
1717
- Writes a default boundary config to `$HOME/.coder-modules/coder/boundary/config/config.yaml` (customizable)
1818
- Automatically adds your Coder deployment domain to the config allowlist
19-
- Exports `BOUNDARY_CONFIG` as a workspace environment variable
2019
- Provides the wrapper path, config path, and script names via outputs
2120

2221
```tf
@@ -39,8 +38,9 @@ The Coder deployment domain is automatically added to the allowlist using
3938
`data.coder_workspace.me.access_url`.
4039

4140
By default the config is written to
42-
`$HOME/.coder-modules/coder/boundary/config/config.yaml` and the
43-
`BOUNDARY_CONFIG` env var points there. You can override it in two ways:
41+
`$HOME/.coder-modules/coder/boundary/config/config.yaml`. You can
42+
access the resolved path via the `boundary_config_path` output. Override
43+
it in two ways:
4444

4545
### Inline config
4646

@@ -68,7 +68,8 @@ module "boundary" {
6868
### External config file
6969

7070
Point to an existing config file in the workspace. The module will not
71-
write any config and `BOUNDARY_CONFIG` will point to your path:
71+
write any config and the `boundary_config_path` output will point to
72+
your path:
7273

7374
```tf
7475
module "boundary" {

registry/coder/modules/boundary/boundary.tftest.hcl

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ run "plan_with_required_vars" {
77
agent_id = "test-agent-id"
88
}
99

10-
# Verify BOUNDARY_CONFIG env var with default config path
11-
assert {
12-
condition = coder_env.boundary_config.name == "BOUNDARY_CONFIG"
13-
error_message = "Environment variable name should be 'BOUNDARY_CONFIG'"
14-
}
15-
16-
assert {
17-
condition = coder_env.boundary_config.value == "$HOME/.coder-modules/coder/boundary/config/config.yaml"
18-
error_message = "BOUNDARY_CONFIG should default to module_directory/config/config.yaml"
19-
}
20-
2110
# Verify the boundary_wrapper_path output
2211
assert {
2312
condition = output.boundary_wrapper_path == "$HOME/.coder-modules/coder/boundary/scripts/boundary-wrapper.sh"
@@ -131,13 +120,7 @@ run "plan_with_inline_boundary_config" {
131120
boundary_config = "allowlist:\n - domain=example.com\nlog_level: debug\n"
132121
}
133122

134-
# BOUNDARY_CONFIG should still point to the managed path since we write
135-
# the inline content there.
136-
assert {
137-
condition = coder_env.boundary_config.value == "$HOME/.coder-modules/coder/boundary/config/config.yaml"
138-
error_message = "BOUNDARY_CONFIG should point to managed config path when using inline config"
139-
}
140-
123+
# Inline config should still point to the managed path.
141124
assert {
142125
condition = output.boundary_config_path == "$HOME/.coder-modules/coder/boundary/config/config.yaml"
143126
error_message = "boundary_config_path output should point to managed config path"
@@ -152,12 +135,7 @@ run "plan_with_boundary_config_path" {
152135
boundary_config_path = "/workspace/my-boundary-config.yaml"
153136
}
154137

155-
# BOUNDARY_CONFIG should point to the user-provided path.
156-
assert {
157-
condition = coder_env.boundary_config.value == "/workspace/my-boundary-config.yaml"
158-
error_message = "BOUNDARY_CONFIG should point to user-provided config path"
159-
}
160-
138+
# boundary_config_path output should point to the user-provided path.
161139
assert {
162140
condition = output.boundary_config_path == "/workspace/my-boundary-config.yaml"
163141
error_message = "boundary_config_path output should point to user-provided path"

registry/coder/modules/boundary/main.test.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,14 @@ describe("boundary", async () => {
136136

137137
const resources = state.resources;
138138

139-
// BOUNDARY_WRAPPER_PATH env should NOT exist (only output)
140-
const wrapperEnv = resources.find(
141-
(r) => r.type === "coder_env" && r.name === "boundary_wrapper_path",
142-
);
143-
expect(wrapperEnv).toBeUndefined();
144-
145-
// Verify coder_env resource for BOUNDARY_CONFIG
146-
const configEnv = resources.find(
147-
(r) => r.type === "coder_env" && r.name === "boundary_config",
148-
);
149-
expect(configEnv).toBeDefined();
150-
expect(configEnv?.instances[0]?.attributes.name).toBe("BOUNDARY_CONFIG");
151-
expect(configEnv?.instances[0]?.attributes.value).toBe(
152-
"$HOME/.coder-modules/coder/boundary/config/config.yaml",
153-
);
139+
// No coder_env resources should exist
140+
const envResources = resources.filter((r) => r.type === "coder_env");
141+
expect(envResources).toHaveLength(0);
154142

155143
// Verify the outputs are set correctly
156144
const coderEnvVars = extractCoderEnvVars(state);
157145
expect(coderEnvVars["BOUNDARY_WRAPPER_PATH"]).toBeUndefined();
158-
expect(coderEnvVars["BOUNDARY_CONFIG"]).toBe(
159-
"$HOME/.coder-modules/coder/boundary/config/config.yaml",
160-
);
146+
expect(coderEnvVars["BOUNDARY_CONFIG"]).toBeUndefined();
161147

162148
// Verify boundary_config_path output
163149
expect(state.outputs["boundary_config_path"]?.value).toBe(
@@ -195,9 +181,8 @@ describe("boundary", async () => {
195181
boundary_config: inlineConfig,
196182
});
197183

198-
const coderEnvVars = extractCoderEnvVars(state);
199184
// Inline config still writes to the managed path.
200-
expect(coderEnvVars["BOUNDARY_CONFIG"]).toBe(
185+
expect(state.outputs["boundary_config_path"]?.value).toBe(
201186
"$HOME/.coder-modules/coder/boundary/config/config.yaml",
202187
);
203188
});
@@ -208,9 +193,10 @@ describe("boundary", async () => {
208193
boundary_config_path: "/workspace/my-config.yaml",
209194
});
210195

211-
const coderEnvVars = extractCoderEnvVars(state);
212-
// BOUNDARY_CONFIG should point to the user-provided path.
213-
expect(coderEnvVars["BOUNDARY_CONFIG"]).toBe("/workspace/my-config.yaml");
196+
// boundary_config_path output should point to the user-provided path.
197+
expect(state.outputs["boundary_config_path"]?.value).toBe(
198+
"/workspace/my-config.yaml",
199+
);
214200
});
215201

216202
test("happy-path-coder-subcommand", async () => {
@@ -337,16 +323,12 @@ describe("boundary", async () => {
337323
expect(installLog).toContain("boundary wrapper configured");
338324
});
339325

340-
test("env-var-set-correctly", async () => {
326+
test("no-env-vars", async () => {
341327
const { coderEnvVars } = await setup();
342328

343-
// BOUNDARY_WRAPPER_PATH env var should NOT exist
329+
// No env vars should be exported by this module.
344330
expect(coderEnvVars["BOUNDARY_WRAPPER_PATH"]).toBeUndefined();
345-
346-
// Verify BOUNDARY_CONFIG is in the coder env vars
347-
expect(coderEnvVars["BOUNDARY_CONFIG"]).toBe(
348-
"$HOME/.coder-modules/coder/boundary/config/config.yaml",
349-
);
331+
expect(coderEnvVars["BOUNDARY_CONFIG"]).toBeUndefined();
350332
});
351333

352334
test("wrapper-script-execution", async () => {

registry/coder/modules/boundary/main.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ variable "boundary_config" {
4747

4848
variable "boundary_config_path" {
4949
type = string
50-
description = "Path to an existing boundary config file in the workspace. When set, no config is written and BOUNDARY_CONFIG points to this path. Mutually exclusive with boundary_config."
50+
description = "Path to an existing boundary config file in the workspace. When set, no config is written and the boundary_config_path output points to this path. Mutually exclusive with boundary_config."
5151
default = null
5252
}
5353

@@ -77,7 +77,7 @@ locals {
7777
coder_domain = try(regex("^https?://([^/:]+)", data.coder_workspace.me.access_url)[0], "")
7878

7979
# Config handling: resolve which config content to write and where
80-
# BOUNDARY_CONFIG points to.
80+
# boundary_config_path output points to.
8181
default_boundary_config = templatefile("${path.module}/config.yaml.tftpl", {
8282
CODER_DOMAIN = local.coder_domain
8383
})
@@ -111,12 +111,6 @@ module "coder_utils" {
111111
install_script = local.install_script
112112
}
113113

114-
resource "coder_env" "boundary_config" {
115-
agent_id = var.agent_id
116-
name = "BOUNDARY_CONFIG"
117-
value = local.effective_boundary_config_path
118-
}
119-
120114
output "boundary_wrapper_path" {
121115
description = "Path to the boundary wrapper script."
122116
value = local.boundary_wrapper_path

0 commit comments

Comments
 (0)