Support multiple default IDEs in JetBrains Gateway

atif/multi-gateway
Muhammad Atif Ali 8 months ago
parent 27e3faf31c
commit 4452630a7e

@ -39,28 +39,22 @@ variable "folder" {
} }
variable "default" { variable "default" {
default = ""
type = string
description = "Default IDE"
}
variable "defaults" {
default = [] default = []
type = list(string) type = list(string)
description = "List of default IDEs to be added to the Workspace page. Conflicts with the default variable." description = "List of default IDEs to be added to the Workspace page."
# check if the list is unique # check if the list is unique
validation { validation {
condition = length(var.defaults) == length(toset(var.defaults)) condition = length(var.default) == length(toset(var.default))
error_message = "The defaults must not contain duplicates." error_message = "The default must not contain duplicates."
} }
# check if defaults are valid jetbrains_ides # check if default are valid jetbrains_ides
validation { validation {
condition = ( condition = (
alltrue([ alltrue([
for code in var.defaults : contains(["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"], code) for code in var.default : contains(["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"], code)
]) ])
) )
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"])}." 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"])}."
} }
} }
@ -144,7 +138,7 @@ variable "jetbrains_ide_versions" {
variable "jetbrains_ides" { variable "jetbrains_ides" {
type = list(string) type = list(string)
description = "The list of IDE product codes to be shown to the user. Does not apply when defaults are used." description = "The list of IDE product codes to be shown to the user. Does not apply when there are multiple defaults."
default = ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"] default = ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD"]
validation { validation {
condition = ( condition = (
@ -259,24 +253,42 @@ locals {
} }
} }
icon = local.jetbrains_ides[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].icon identifier = try([data.coder_parameter.jetbrains_ide[0].value], var.default)
json_data = var.latest ? jsondecode(data.http.jetbrains_ide_versions[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].response_body) : {} list_json_data = var.latest ? [
key = var.latest ? keys(local.json_data)[0] : "" for ide in local.identifier : jsondecode(data.http.jetbrains_ide_versions[ide].response_body)
display_name = local.jetbrains_ides[try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0])].name ] : []
identifier = try(data.coder_parameter.jetbrains_ide[0].value, var.defaults[0]) list_key = var.latest ? [
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 for j in local.list_json_data : keys(j)[0]
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 ] : []
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 download_links = length(local.list_key) > 0 ? [
for i, j in local.list_json_data : j[local.list_key[i]][0].downloads.linux.link
] : [
for ide in local.identifier : local.jetbrains_ides[ide].download_link
]
build_numbers = length(local.list_key) > 0 ? [
for i, j in local.list_json_data : j[local.list_key[i]][0].build
] : [
for ide in local.identifier : local.jetbrains_ides[ide].build_number
]
versions = length(local.list_key) > 0 ? [
for i, j in local.list_json_data : j[local.list_key[i]][0].version
] : [
for ide in local.identifier : local.jetbrains_ides[ide].version
]
display_names = [for key in keys(coder_app.gateway) : coder_app.gateway[key].display_name]
icons = [for key in keys(coder_app.gateway) : coder_app.gateway[key].icon]
urls = [for key in keys(coder_app.gateway) : coder_app.gateway[key].url]
} }
data "coder_parameter" "jetbrains_ide" { data "coder_parameter" "jetbrains_ide" {
count = length(var.defaults) > 0 ? 0 : 1 # remove the coder_parameter if there are multiple default
count = length(var.default) > 1 ? 0 : 1
type = "string" type = "string"
name = "jetbrains_ide" name = "jetbrains_ide"
display_name = "JetBrains IDE" display_name = "JetBrains IDE"
icon = "/icon/gateway.svg" icon = "/icon/gateway.svg"
mutable = true mutable = true
default = var.default == "" ? var.jetbrains_ides[0] : var.default default = length(var.default) > 0 ? var.default[0] : var.jetbrains_ides[0]
order = var.coder_parameter_order order = var.coder_parameter_order
dynamic "option" { dynamic "option" {
@ -293,7 +305,7 @@ data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {} data "coder_workspace_owner" "me" {}
resource "coder_app" "gateway" { resource "coder_app" "gateway" {
for_each = length(var.defaults) > 0 ? toset(var.defaults) : toset([data.coder_parameter.jetbrains_ide[0].value]) for_each = length(var.default) > 1 ? toset(var.default) : toset([data.coder_parameter.jetbrains_ide[0].value])
agent_id = var.agent_id agent_id = var.agent_id
slug = var.slug slug = var.slug
display_name = local.jetbrains_ides[each.value].name display_name = local.jetbrains_ides[each.value].name
@ -328,31 +340,31 @@ output "identifier" {
} }
output "display_name" { output "display_name" {
value = local.display_name value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].display_name]
description = "The display name of the JetBrains IDE." description = "The display name of the JetBrains IDE."
} }
output "icon" { output "icon" {
value = local.icon value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].icon]
description = "The icon of the JetBrains IDE." description = "The icon of the JetBrains IDE."
} }
output "download_link" { output "download_link" {
value = local.download_link value = local.download_links
description = "The download link of the JetBrains IDE." description = "The download link of the JetBrains IDE."
} }
output "build_number" { output "build_number" {
value = local.build_number value = local.build_numbers
description = "The build number of the JetBrains IDE." description = "The build number of the JetBrains IDE."
} }
output "version" { output "version" {
value = local.version value = local.versions
description = "The version of the JetBrains IDE." description = "The version of the JetBrains IDE."
} }
output "url" { output "url" {
value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].url] value = [for key in keys(coder_app.gateway) : coder_app.gateway[key].url]
description = "The URLs to connect to the JetBrains IDEs." description = "The URL to connect to the JetBrains IDE."
} }
Loading…
Cancel
Save