Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions registry/coder/modules/zed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ module "zed" {
order = 1
}
```

### With custom agent name

```tf
module "zed" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/zed/coder"
version = "1.0.0"
agent_id = coder_agent.example.id
agent_name = coder_agent.example.name
}
```
14 changes: 12 additions & 2 deletions registry/coder/modules/zed/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
agent_id: "foo",
});
expect(state.outputs.zed_url.value).toBe(
"zed://ssh/default.default.coder/",
"zed://ssh/default.coder",
);

const coder_app = state.resources.find(
Expand All @@ -34,8 +34,8 @@
agent_id: "foo",
folder: "/foo/bar",
});
expect(state.outputs.zed_url.value).toBe(

Check failure on line 37 in registry/coder/modules/zed/main.test.ts

View workflow job for this annotation

GitHub Actions / Validate Terraform output

error: expect(received).toBe(expected)

Expected: "zed://ssh/default.coder/foo/bar" Received: "zed://ssh/default.coder//foo/bar" at <anonymous> (/home/runner/work/registry/registry/registry/coder/modules/zed/main.test.ts:37:41)
"zed://ssh/default.default.coder/foo/bar",
"zed://ssh/default.coder/foo/bar",
);
});

Expand Down Expand Up @@ -68,4 +68,14 @@
expect(coder_app?.instances.length).toBe(1);
expect(coder_app?.instances[0].attributes.display_name).toBe("Custom Zed");
});

it("adds agent_name to hostname", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
agent_name: "myagent",
});
expect(state.outputs.zed_url.value).toBe(
"zed://ssh/myagent.default.me.coder",
);
});
});
12 changes: 9 additions & 3 deletions registry/coder/modules/zed/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ variable "agent_id" {
description = "The ID of a Coder agent."
}

variable "agent_name" {
type = string
description = "The name of the agent."
default = ""
}

variable "folder" {
type = string
description = "The folder to open in Zed IDE."
Expand Down Expand Up @@ -49,8 +55,8 @@ data "coder_workspace_owner" "me" {}

locals {
workspace_name = lower(data.coder_workspace.me.name)
owner_name = lower(data.coder_workspace_owner.me.name)
hostname = "${local.workspace_name}.${local.owner_name}.coder"
agent_name = lower(var.agent_name)
hostname = var.agent_name != "" ? "${local.agent_name}.${local.workspace_name}.me.coder" : "${local.workspace_name}.coder"
}

resource "coder_app" "zed" {
Expand All @@ -61,7 +67,7 @@ resource "coder_app" "zed" {
external = true
order = var.order
group = var.group
url = "zed://ssh/${local.hostname}/${var.folder}"
url = "zed://ssh/${local.hostname}${var.folder != "" ? "/${var.folder}" : ""}"
}

output "zed_url" {
Expand Down
Loading