Skip to content
49 changes: 43 additions & 6 deletions registry/coder/modules/jetbrains-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Consult the [JetBrains documentation](https://www.jetbrains.com/help/idea/prereq
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.2"
version = "1.2.3"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["CL", "GO", "IU", "PY", "WS"]
Expand All @@ -35,21 +35,58 @@ module "jetbrains_gateway" {
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.2"
version = "1.2.3"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
default = "GO"
}
```

### Embed the agent name in the Gateway URL

This can be used when support for connecting to multiple agents within one workspace is required.

To utilise this both `embed_agent_name` and `agent_name` must be populated on each instance of the module.
In addition each instance must have a unique `slug` and `ide_parameter_name` variable defined.

```tf
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.3"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["CL", "GO"]
default = "GO"
embed_agent_name = true
agent_name = "main"
ide_parameter_name = "jetbrains_ide" # default variable value
slug = "gateway" # default variable value
}

module "jetbrains_gateway_agent2" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.3"
agent_id = coder_agent.jetbrainsagent2.id
folder = "/home/coder/example"
jetbrains_ides = ["CL", "GO", "IU", "PY", "WS"]
default = "GO"
embed_agent_name = true
agent_name = "jetbrainsagent2"
ide_parameter_name = "jetbrains_ide_agent2"
slug = "gateway-agent2"
}
```

### Use the latest version of each IDE

```tf
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.2"
version = "1.2.3"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["IU", "PY"]
Expand All @@ -64,7 +101,7 @@ module "jetbrains_gateway" {
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.2"
version = "1.2.3"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["IU", "PY"]
Expand All @@ -89,7 +126,7 @@ module "jetbrains_gateway" {
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.2"
version = "1.2.3"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
Expand All @@ -107,7 +144,7 @@ Due to the highest priority of the `ide_download_link` parameter in the `(jetbra
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.2"
version = "1.2.3"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
Expand Down
15 changes: 14 additions & 1 deletion registry/coder/modules/jetbrains-gateway/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("jetbrains-gateway", async () => {
folder: "/home/coder",
});
expect(state.outputs.url.value).toBe(
"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",
"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",
);

const coder_app = state.resources.find(
Expand All @@ -40,4 +40,17 @@ describe("jetbrains-gateway", async () => {
});
expect(state.outputs.identifier.value).toBe("IU");
});

it("optionally includes agent when embed_agent_name is true", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
agent_name: "main",
folder: "/home/coder",
embed_agent_name: true,
});

expect(state.outputs.url.value).toBe(
"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",
);
});
});
25 changes: 17 additions & 8 deletions registry/coder/modules/jetbrains-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ variable "slug" {

variable "agent_name" {
type = string
description = "Agent name. (unused). Will be removed in a future version"

default = ""
description = "Agent name."
default = ""
}

variable "folder" {
Expand Down Expand Up @@ -68,6 +67,18 @@ variable "group" {
default = null
}

variable "embed_agent_name" {
type = bool
description = "Embed the agent name in the JetBrains Gateway URL when support for multiple agents is required."
default = false
}

variable "ide_parameter_name" {
type = string
description = "Terraform parameter name for the JetBrains IDE selector. Must be unique per module instance."
default = "jetbrains_ide"
}

variable "coder_parameter_order" {
type = number
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)."
Expand Down Expand Up @@ -303,7 +314,7 @@ locals {

data "coder_parameter" "jetbrains_ide" {
type = "string"
name = "jetbrains_ide"
name = var.ide_parameter_name
display_name = "JetBrains IDE"
icon = "/icon/gateway.svg"
mutable = true
Expand Down Expand Up @@ -331,7 +342,7 @@ resource "coder_app" "gateway" {
external = true
order = var.order
group = var.group
url = join("", [
url = join("", concat([
"jetbrains-gateway://connect#type=coder&workspace=",
data.coder_workspace.me.name,
"&owner=",
Expand All @@ -348,9 +359,7 @@ resource "coder_app" "gateway" {
local.build_number,
"&ide_download_link=",
local.download_link,
"&agent_id=",
var.agent_id,
])
], var.embed_agent_name && trimspace(var.agent_name) != "" ? ["&agent=", var.agent_name] : []))
}

output "identifier" {
Expand Down
Loading