From ef10dcfc67f1a38b41e8dc684714e0cc1e21cc84 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 8 Nov 2024 23:11:20 +0500 Subject: [PATCH] Support multiple default IDEs in JetBrains Gateway Refactor the `default` variable to accept a list, enabling the specification of multiple default IDEs. This change allows users to manage configurations for multiple IDEs more efficiently. - Updated `default` type from string to list(string) - Iterated over default IDEs to generate corresponding resources - Ensured backward compatibility where single IDE configs were used --- jetbrains-gateway/README.md | 26 +++++++++--- jetbrains-gateway/main.tf | 82 ++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/jetbrains-gateway/README.md b/jetbrains-gateway/README.md index 00beb83..2445f94 100644 --- a/jetbrains-gateway/README.md +++ b/jetbrains-gateway/README.md @@ -19,7 +19,7 @@ module "jetbrains_gateway" { agent_name = "example" folder = "/home/coder/example" jetbrains_ides = ["CL", "GO", "IU", "PY", "WS"] - default = "GO" + default = ["GO"] } ``` @@ -37,7 +37,7 @@ module "jetbrains_gateway" { agent_name = "example" folder = "/home/coder/example" jetbrains_ides = ["GO", "WS"] - default = "GO" + default = ["GO"] } ``` @@ -51,7 +51,7 @@ module "jetbrains_gateway" { agent_name = "example" folder = "/home/coder/example" jetbrains_ides = ["GO", "WS"] - default = "GO" + default = ["GO"] latest = true } ``` @@ -66,13 +66,27 @@ module "jetbrains_gateway" { agent_name = "example" folder = "/home/coder/example" jetbrains_ides = ["GO", "WS"] - default = "GO" + default = ["GO"] latest = true channel = "eap" } ``` -### Custom base link +### Add Multiple IDEs with the default set to GoLand + +```tf +module "jetbrains_gateway" { + source = "registry.coder.com/modules/jetbrains-gateway/coder" + version = "1.0.23" + agent_id = coder_agent.example.id + agent_name = "example" + folder = "/home/coder/example" + jetbrains_ides = ["GO", "WS", "RD", "PY"] + default = ["GO", "PY"] +} +``` + +### Custom release download link Due to the highest priority of the `ide_download_link` parameter in the `(jetbrains-gateway://...` within IDEA, the pre-configured download address will be overridden when using [IDEA's offline mode](https://www.jetbrains.com/help/idea/fully-offline-mode.html). Therefore, it is necessary to configure the `download_base_link` parameter for the `jetbrains_gateway` module to change the value of `ide_download_link`. @@ -86,7 +100,7 @@ module "jetbrains_gateway" { jetbrains_ides = ["GO", "WS"] releases_base_link = "https://releases.internal.site/" download_base_link = "https://download.internal.site/" - default = "GO" + default = ["GO"] } ``` diff --git a/jetbrains-gateway/main.tf b/jetbrains-gateway/main.tf index 24bf476..5044b2f 100644 --- a/jetbrains-gateway/main.tf +++ b/jetbrains-gateway/main.tf @@ -20,7 +20,7 @@ variable "agent_id" { variable "slug" { type = string - description = "The slug for the coder_app. Allows resuing the module with the same template." + description = "The slug for the coder_app" default = "gateway" } @@ -39,9 +39,9 @@ variable "folder" { } variable "default" { - default = "" - type = string - description = "Default IDE" + default = [] + type = list(string) + description = "Default IDEs to be added to the Workspace page." } variable "order" { @@ -166,6 +166,12 @@ variable "download_base_link" { } } +variable "provide_options" { + type = bool + description = "Whether to provide coder_parameter options." + default = true +} + data "http" "jetbrains_ide_versions" { for_each = var.latest ? toset(var.jetbrains_ides) : toset([]) url = "${var.releases_base_link}/products/releases?code=${each.key}&latest=true&type=${var.channel}" @@ -239,23 +245,19 @@ locals { } } - icon = local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].icon - json_data = var.latest ? jsondecode(data.http.jetbrains_ide_versions[data.coder_parameter.jetbrains_ide.value].response_body) : {} - key = var.latest ? keys(local.json_data)[0] : "" - display_name = local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].name - identifier = data.coder_parameter.jetbrains_ide.value - download_link = var.latest ? local.json_data[local.key][0].downloads.linux.link : local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].download_link - build_number = var.latest ? local.json_data[local.key][0].build : local.jetbrains_ides[data.coder_parameter.jetbrains_ide.value].build_number - version = var.latest ? local.json_data[local.key][0].version : var.jetbrains_ide_versions[data.coder_parameter.jetbrains_ide.value].version + default_ide_map = { + for ide in var.default : ide => local.jetbrains_ides[ide] + } } data "coder_parameter" "jetbrains_ide" { + for_each = local.default_ide_map type = "string" - name = "jetbrains_ide" - display_name = "JetBrains IDE" + name = "jetbrains_ide_${each.key}" + display_name = "JetBrains IDE ${each.key}" icon = "/icon/gateway.svg" mutable = true - default = var.default == "" ? var.jetbrains_ides[0] : var.default + default = each.key order = var.coder_parameter_order dynamic "option" { @@ -272,10 +274,11 @@ data "coder_workspace" "me" {} data "coder_workspace_owner" "me" {} resource "coder_app" "gateway" { + for_each = local.default_ide_map agent_id = var.agent_id - slug = var.slug - display_name = local.display_name - icon = local.icon + slug = "${var.slug}_${each.key}" + display_name = each.value.name + icon = each.value.icon external = true order = var.order url = join("", [ @@ -292,38 +295,23 @@ resource "coder_app" "gateway" { "&token=", "$SESSION_TOKEN", "&ide_product_code=", - data.coder_parameter.jetbrains_ide.value, + each.key, "&ide_build_number=", - local.build_number, + each.value.build_number, "&ide_download_link=", - local.download_link, + each.value.download_link, ]) } -output "identifier" { - value = local.identifier -} - -output "display_name" { - value = local.display_name -} - -output "icon" { - value = local.icon -} - -output "download_link" { - value = local.download_link -} - -output "build_number" { - value = local.build_number -} - -output "version" { - value = local.version -} - -output "url" { - value = coder_app.gateway.url +output "coder_apps" { + value = { + for key, app in coder_app.gateway : key => { + identifier = key + display_name = app.display_name + icon = app.icon + download_link = app.url + build_number = app.build_number + version = app.version + } + } }