Skip to content

Commit fc7cc77

Browse files
committed
rework to use agent name
1 parent 0926bdf commit fc7cc77

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

registry/coder/modules/jetbrains-gateway/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,43 @@ module "jetbrains_gateway" {
4343
}
4444
```
4545

46+
### Embed the agent name in the Gateway URL
47+
48+
This can be used when support for connecting to multiple agents within one workspace is required.
49+
50+
To utilise this both `embed_agent_id` and `agent_name` must be populated on each instance of the module.
51+
In addition each instance must have a unique `slug` and `ide_parameter_name` variable defined.
52+
53+
```tf
54+
module "jetbrains_gateway" {
55+
count = data.coder_workspace.me.start_count
56+
source = "registry.coder.com/coder/jetbrains-gateway/coder"
57+
version = "1.2.3"
58+
agent_id = coder_agent.example.id
59+
folder = "/home/coder/example"
60+
jetbrains_ides = ["CL", "GO"]
61+
default = "GO"
62+
embed_agent_id = true
63+
agent_name = "main"
64+
ide_parameter_name = "jetbrains_ide" # default variable value
65+
slug = "gateway" # default variable value
66+
}
67+
68+
module "jetbrains_gateway_agent2" {
69+
count = data.coder_workspace.me.start_count
70+
source = "registry.coder.com/coder/jetbrains-gateway/coder"
71+
version = "1.2.3"
72+
agent_id = coder_agent.jetbrainsagent2.id
73+
folder = "/home/coder/example"
74+
jetbrains_ides = ["CL", "GO", "IU", "PY", "WS"]
75+
default = "GO"
76+
embed_agent_id = true
77+
agent_name = "jetbrainsagent2"
78+
ide_parameter_name = "jetbrains_ide_agent2"
79+
slug = "gateway-agent2"
80+
}
81+
```
82+
4683
### Use the latest version of each IDE
4784

4885
```tf

registry/coder/modules/jetbrains-gateway/main.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ describe("jetbrains-gateway", async () => {
4040
});
4141
expect(state.outputs.identifier.value).toBe("IU");
4242
});
43-
});
44-
it("optionally includes agent_id when embed_agent_id is true", async () => {
45-
const state = await runTerraformApply(import.meta.dir, {
46-
agent_id: "foo",
47-
folder: "/home/coder",
48-
embed_agent_id: true,
49-
});
5043

51-
expect(state.outputs.url.value).toBe(
52-
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz&agent_id=foo",
53-
);
44+
it("optionally includes agent when embed_agent_id is true", async () => {
45+
const state = await runTerraformApply(import.meta.dir, {
46+
agent_id: "foo",
47+
agent_name: "main",
48+
folder: "/home/coder",
49+
embed_agent_id: true,
50+
});
51+
52+
expect(state.outputs.url.value).toBe(
53+
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz&agent=main",
54+
);
55+
});
5456
});

registry/coder/modules/jetbrains-gateway/main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ variable "group" {
7070

7171
variable "embed_agent_id" {
7272
type = bool
73-
description = "Append the agent_id to the JetBrains Gateway URL for when support for multiple agents is required."
73+
description = "Embed the agent name in the JetBrains Gateway URL when support for multiple agents is required."
7474
default = false
7575
}
7676

77+
variable "ide_parameter_name" {
78+
type = string
79+
description = "Terraform parameter name for the JetBrains IDE selector. Must be unique per module instance."
80+
default = "jetbrains_ide"
81+
}
82+
7783
variable "coder_parameter_order" {
7884
type = number
7985
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
@@ -309,7 +315,7 @@ locals {
309315

310316
data "coder_parameter" "jetbrains_ide" {
311317
type = "string"
312-
name = "jetbrains_ide"
318+
name = var.ide_parameter_name
313319
display_name = "JetBrains IDE"
314320
icon = "/icon/gateway.svg"
315321
mutable = true
@@ -354,7 +360,7 @@ resource "coder_app" "gateway" {
354360
local.build_number,
355361
"&ide_download_link=",
356362
local.download_link,
357-
], var.embed_agent_id && trimspace(var.agent_id) != "" ? ["&agent_id=", var.agent_id] : []))
363+
], var.embed_agent_id && trimspace(var.agent_name) != "" ? ["&agent=", var.agent_name] : []))
358364
}
359365

360366
output "identifier" {

0 commit comments

Comments
 (0)