improve default logic

pull/53/head
Muhammad Atif Ali 2 years ago
parent 868e38fbda
commit 780c1d20c3
No known key found for this signature in database

@ -11,6 +11,15 @@ tags: [ide, jetbrains, helper, parameter]
This module adds a JetBrains Gateway Button to open any workspace with a single click. This module adds a JetBrains Gateway Button to open any workspace with a single click.
```hcl
module "jetbrains_gateway" {
source = "https://registry.coder.com/modules/jetbrains-gateway"
agent_id = coder_agent.example.id
agent_name = "example"
project_directory = "/home/coder/example"
jetbrains_ides = ["GO", "WS", "IU", "IC", "PY", "PC", "PS", "CL", "RM", "DB", "RD"]
}
![JetBrains Gateway IDes list](../.images/jetbrains-gateway.png) ![JetBrains Gateway IDes list](../.images/jetbrains-gateway.png)
## Examples ## Examples

@ -25,6 +25,7 @@ variable "project_directory" {
} }
variable "default" { variable "default" {
default = null
type = string type = string
description = "Default IDE" description = "Default IDE"
} }
@ -40,6 +41,16 @@ variable "jetbrains_ides" {
) )
error_message = "The jetbrains_ides must be 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"
} }
# check if the list is empty
validation {
condition = length(var.jetbrains_ides) > 0
error_message = "The jetbrains_ides must not be empty."
}
#ccheck if the list contains duplicates
validation {
condition = length(var.jetbrains_ides) == length(set(var.jetbrains_ides))
error_message = "The jetbrains_ides must not contain duplicates."
}
} }
locals { locals {
@ -108,7 +119,8 @@ data "coder_parameter" "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 != null && var.default != "" ? local.jetbrains_ides[var.default].value : null # check if default is in the jet_brains_ides list and if it is not empty or null otherwise set it to null
default = contains(var.jetbrains_ides.keys, var.default) && var.default != null && var.default != "" ? var.default : null
dynamic "option" { dynamic "option" {
for_each = { for key, value in local.jetbrains_ides : key => value if contains(var.jetbrains_ides, key) } for_each = { for key, value in local.jetbrains_ides : key => value if contains(var.jetbrains_ides, key) }

Loading…
Cancel
Save