From 65cd628d92c1e16799324c1b8239259a6a9e6281 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Sep 2023 11:51:04 +0300 Subject: [PATCH] renmae variables --- jetbrains-gateway/main.tf | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/jetbrains-gateway/main.tf b/jetbrains-gateway/main.tf index 993ea41..545fe68 100644 --- a/jetbrains-gateway/main.tf +++ b/jetbrains-gateway/main.tf @@ -24,23 +24,28 @@ variable "project_directory" { description = "The directory to open in the IDE. e.g. /home/coder/project" } -variable "gateway_ide_product_code" { +variable "default" { + type = string + description = "Default IDE" + default = null +} + +variable "jetbrains_ides" { type = list(string) - description = "The list of IDE product codes, e.g. ['GO', 'WS'] or ['ALL']" - default = ["ALL"] + description = "The list of IDE product codes, e.g. ["GO", "WS"] + default = var.default != null && var.default != "" ? var.default : null validation { condition = ( - length(var.gateway_ide_product_code) == 1 && var.gateway_ide_product_code[0] == "ALL" || alltrue([ - for code in var.gateway_ide_product_code : contains(["IU", "IC", "PS", "WS", "PY", "PC", "CL", "GO", "DB", "RD", "RM"], code) + for code in var.jetbrains_ides : contains(["IU", "IC", "PS", "WS", "PY", "PC", "CL", "GO", "DB", "RD", "RM"], code) ]) ) - error_message = "The gateway_ide_product_code must be ['ALL'] or a list of valid product codes. https://plugins.jetbrains.com/docs/marketplace/product-codes.html" + error_message = "The jetbrains_ides must be a list of valid product codes. https://plugins.jetbrains.com/docs/marketplace/product-codes.html" } } locals { - gateway_ides = { + jetbrains_ides = { "GO" = { icon = "/icon/goland.svg", name = "GoLand", @@ -108,7 +113,7 @@ data "coder_parameter" "jetbrains_ide" { default = local.gateway_ides["GO"].value dynamic "option" { - for_each = contains(var.gateway_ide_product_code, "ALL") ? local.gateway_ides : { for key, value in local.gateway_ides : key => value if contains(var.gateway_ide_product_code, key) } + for_each = { for key, value in local.gateway_ides : key => value if contains(var.jetbrains_ides, key) } content { icon = option.value.icon name = option.value.name @@ -127,3 +132,7 @@ resource "coder_app" "gateway" { icon = data.coder_parameter.jetbrains_ide.option[index(data.coder_parameter.jetbrains_ide.option.*.value, data.coder_parameter.jetbrains_ide.value)].icon external = true } + +output "jetbrains_ides" { + value = data.coder_parameter.jetbrains_ide.value +}