Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 4452630

Browse files
committed
Support multiple default IDEs in JetBrains Gateway
1 parent 27e3faf commit 4452630

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

jetbrains-gateway/main.tf

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,22 @@ variable "folder" {
3939
}
4040

4141
variable "default" {
42-
default = ""
43-
type = string
44-
description = "Default IDE"
45-
}
46-
47-
variable "defaults" {
4842
default = []
4943
type = list(string)
50-
description = "List of default IDEs to be added to the Workspace page. Conflicts with the default variable."
44+
description = "List of default IDEs to be added to the Workspace page."
5145
# check if the list is unique
5246
validation {
53-
condition = length(var.defaults) == length(toset(var.defaults))
54-
error_message = "The defaults must not contain duplicates."
47+
condition = length(var.default) == length(toset(var.default))
48+
error_message = "The default must not contain duplicates."
5549
}
56-
# check if defaults are valid jetbrains_ides
50+
# check if default are valid jetbrains_ides
5751
validation {
5852
condition = (
5953
alltrue([
60-
for code in var.defaults : contains(["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"], code)
54+
for code in var.default : contains(["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"], code)
6155
])
6256
)
63-
error_message = "The defaults must be a list of valid product codes. Valid product codes are ${join(",", ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"])}."
57+
error_message = "The default must be a list of valid product codes. Valid product codes are ${join(",", ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"])}."
6458
}
6559
}
6660

@@ -144,7 +138,7 @@ variable "jetbrains_ide_versions" {
144138

145139
variable "jetbrains_ides" {
146140
type = list(string)
147-
description = "The list of IDE product codes to be shown to the user. Does not apply when defaults are used."
141+
description = "The list of IDE product codes to be shown to the user. Does not apply when there are multiple defaults."
148142
default = ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"]
149143
validation {
150144
condition = (
@@ -259,24 +253,42 @@ locals {
259253
}
260254
}
261255

262-
icon = local.jetbrains_ides[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].icon
263-
json_data = var.latest ? jsondecode(data.http.jetbrains_ide_versions[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].response_body) : {}
264-
key = var.latest ? keys(local.json_data)[0] : ""
265-
display_name = local.jetbrains_ides[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].name
266-
identifier = try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])
267-
download_link = var.latest ? local.json_data[local.key][0].downloads.linux.link : local.jetbrains_ides[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].download_link
268-
build_number = var.latest ? local.json_data[local.key][0].build : local.jetbrains_ides[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].build_number
269-
version = var.latest ? local.json_data[local.key][0].version : var.jetbrains_ide_versions[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].version
256+
identifier = try([data.coder_parameter.jetbrains_ide[0].value], var.default)
257+
list_json_data = var.latest ? [
258+
for ide in local.identifier : jsondecode(data.http.jetbrains_ide_versions[ide].response_body)
259+
] : []
260+
list_key = var.latest ? [
261+
for j in local.list_json_data : keys(j)[0]
262+
] : []
263+
download_links = length(local.list_key) > 0 ? [
264+
for i, j in local.list_json_data : j[local.list_key[i]][0].downloads.linux.link
265+
] : [
266+
for ide in local.identifier : local.jetbrains_ides[ide].download_link
267+
]
268+
build_numbers = length(local.list_key) > 0 ? [
269+
for i, j in local.list_json_data : j[local.list_key[i]][0].build
270+
] : [
271+
for ide in local.identifier : local.jetbrains_ides[ide].build_number
272+
]
273+
versions = length(local.list_key) > 0 ? [
274+
for i, j in local.list_json_data : j[local.list_key[i]][0].version
275+
] : [
276+
for ide in local.identifier : local.jetbrains_ides[ide].version
277+
]
278+
display_names = [for key in keys(coder_app.gateway) : coder_app.gateway[key].display_name]
279+
icons = [for key in keys(coder_app.gateway) : coder_app.gateway[key].icon]
280+
urls = [for key in keys(coder_app.gateway) : coder_app.gateway[key].url]
270281
}
271282

272283
data "coder_parameter" "jetbrains_ide" {
273-
count = length(var.defaults) > 0 ? 0 : 1
284+
# remove the coder_parameter if there are multiple default
285+
count = length(var.default) > 1 ? 0 : 1
274286
type = "string"
275287
name = "jetbrains_ide"
276288
display_name = "JetBrains IDE"
277289
icon = "/icon/gateway.svg"
278290
mutable = true
279-
default = var.default == "" ? var.jetbrains_ides[0] : var.default
291+
default = length(var.default) > 0 ? var.default[0] : var.jetbrains_ides[0]
280292
order = var.coder_parameter_order
281293

282294
dynamic "option" {
@@ -293,7 +305,7 @@ data "coder_workspace" "me" {}
293305
data "coder_workspace_owner" "me" {}
294306

295307
resource "coder_app" "gateway" {
296-
for_each = length(var.defaults) > 0 ? toset(var.defaults) : toset([data.coder_parameter.jetbrains_ide[0].value])
308+
for_each = length(var.default) > 1 ? toset(var.default) : toset([data.coder_parameter.jetbrains_ide[0].value])
297309
agent_id = var.agent_id
298310
slug = var.slug
299311
display_name = local.jetbrains_ides[each.value].name
@@ -328,31 +340,31 @@ output "identifier" {
328340
}
329341

330342
output "display_name" {
331-
value = local.display_name
343+
value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].display_name]
332344
description = "The display name of the JetBrains IDE."
333345
}
334346

335347
output "icon" {
336-
value = local.icon
348+
value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].icon]
337349
description = "The icon of the JetBrains IDE."
338350
}
339351

340352
output "download_link" {
341-
value = local.download_link
353+
value = local.download_links
342354
description = "The download link of the JetBrains IDE."
343355
}
344356

345357
output "build_number" {
346-
value = local.build_number
358+
value = local.build_numbers
347359
description = "The build number of the JetBrains IDE."
348360
}
349361

350362
output "version" {
351-
value = local.version
363+
value = local.versions
352364
description = "The version of the JetBrains IDE."
353365
}
354366

355367
output "url" {
356368
value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].url]
357-
description = "The URLs to connect to the JetBrains IDEs."
369+
description = "The URL to connect to the JetBrains IDE."
358370
}

0 commit comments

Comments
 (0)