Skip to content

Commit 225f180

Browse files
Fix Zed module URL construction and add agent_name variable
- Add agent_name variable to match original dogfood module - Fix URL construction to avoid double slashes when folder is provided - Update hostname logic to use agent_name when provided - Add test for agent_name functionality - Update README with agent_name example Fixes the failing test: zed > adds folder Co-authored-by: matifali <[email protected]>
1 parent 11ebb4a commit 225f180

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

registry/coder/modules/zed/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,15 @@ module "zed" {
4848
order = 1
4949
}
5050
```
51+
52+
### With custom agent name
53+
54+
```tf
55+
module "zed" {
56+
count = data.coder_workspace.me.start_count
57+
source = "registry.coder.com/coder/zed/coder"
58+
version = "1.0.0"
59+
agent_id = coder_agent.example.id
60+
agent_name = coder_agent.example.name
61+
}
62+
```

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe("zed", async () => {
1717
agent_id: "foo",
1818
});
1919
expect(state.outputs.zed_url.value).toBe(
20-
"zed://ssh/default.default.coder/",
20+
"zed://ssh/default.coder",
2121
);
2222

2323
const coder_app = state.resources.find(
@@ -35,7 +35,7 @@ describe("zed", async () => {
3535
folder: "/foo/bar",
3636
});
3737
expect(state.outputs.zed_url.value).toBe(
38-
"zed://ssh/default.default.coder/foo/bar",
38+
"zed://ssh/default.coder/foo/bar",
3939
);
4040
});
4141

@@ -68,4 +68,14 @@ describe("zed", async () => {
6868
expect(coder_app?.instances.length).toBe(1);
6969
expect(coder_app?.instances[0].attributes.display_name).toBe("Custom Zed");
7070
});
71+
72+
it("adds agent_name to hostname", async () => {
73+
const state = await runTerraformApply(import.meta.dir, {
74+
agent_id: "foo",
75+
agent_name: "myagent",
76+
});
77+
expect(state.outputs.zed_url.value).toBe(
78+
"zed://ssh/myagent.default.me.coder",
79+
);
80+
});
7181
});

registry/coder/modules/zed/main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ variable "agent_id" {
1414
description = "The ID of a Coder agent."
1515
}
1616

17+
variable "agent_name" {
18+
type = string
19+
description = "The name of the agent."
20+
default = ""
21+
}
22+
1723
variable "folder" {
1824
type = string
1925
description = "The folder to open in Zed IDE."
@@ -49,8 +55,8 @@ data "coder_workspace_owner" "me" {}
4955

5056
locals {
5157
workspace_name = lower(data.coder_workspace.me.name)
52-
owner_name = lower(data.coder_workspace_owner.me.name)
53-
hostname = "${local.workspace_name}.${local.owner_name}.coder"
58+
agent_name = lower(var.agent_name)
59+
hostname = var.agent_name != "" ? "${local.agent_name}.${local.workspace_name}.me.coder" : "${local.workspace_name}.coder"
5460
}
5561

5662
resource "coder_app" "zed" {
@@ -61,7 +67,7 @@ resource "coder_app" "zed" {
6167
external = true
6268
order = var.order
6369
group = var.group
64-
url = "zed://ssh/${local.hostname}/${var.folder}"
70+
url = "zed://ssh/${local.hostname}${var.folder != "" ? "/${var.folder}" : ""}"
6571
}
6672

6773
output "zed_url" {

0 commit comments

Comments
 (0)