chore: allowed empty default for modules (#72)
From #66, also added testing for `jetbrains-gateway`. ## Regions Azure and AWS were simple, but there is no error message when no region is selected: https://github.com/coder/modules/assets/58410745/9a9e317b-7764-427f-b298-86313de5fb33 Open to feedback on this. ## Jetbrains Gateway The Jetbrains gateway default IDE satisfies a ton of logic in the template, so allowing `null` would lead to a lot of patchwork `try` statements. Now it's implemented to use the first IDE in the `jetbrains_ides` as the coder_parameter default for cleanliness. Let me know your thoughts.
This commit is contained in:
@@ -13,11 +13,11 @@ This module adds a JetBrains Gateway Button to open any workspace with a single
|
||||
|
||||
```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"]
|
||||
source = "https://registry.coder.com/modules/jetbrains-gateway"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
folder = "/home/coder/example"
|
||||
jetbrains_ides = ["GO", "WS", "IU", "IC", "PY", "PC", "PS", "CL", "RM", "DB", "RD"]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -29,12 +29,12 @@ module "jetbrains_gateway" {
|
||||
|
||||
```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"]
|
||||
default = "GO"
|
||||
source = "https://registry.coder.com/modules/jetbrains-gateway"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
folder = "/home/coder/example"
|
||||
jetbrains_ides = ["GO", "WS"]
|
||||
default = "GO"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
16
jetbrains-gateway/main.test.ts
Normal file
16
jetbrains-gateway/main.test.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { describe } from "bun:test";
|
||||
import {
|
||||
runTerraformInit,
|
||||
testRequiredVariables,
|
||||
} from "../test";
|
||||
|
||||
describe("jetbrains-gateway`", async () => {
|
||||
await runTerraformInit(import.meta.dir);
|
||||
|
||||
await testRequiredVariables(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
agent_name: "bar",
|
||||
folder: "/baz/",
|
||||
jetbrains_ides: '["IU", "IC", "PY"]',
|
||||
});
|
||||
});
|
||||
@@ -19,13 +19,13 @@ variable "agent_name" {
|
||||
description = "The name of a Coder agent."
|
||||
}
|
||||
|
||||
variable "project_directory" {
|
||||
variable "folder" {
|
||||
type = string
|
||||
description = "The directory to open in the IDE. e.g. /home/coder/project"
|
||||
}
|
||||
|
||||
variable "default" {
|
||||
default = null
|
||||
default = ""
|
||||
type = string
|
||||
description = "Default IDE"
|
||||
}
|
||||
@@ -46,7 +46,7 @@ variable "jetbrains_ides" {
|
||||
condition = length(var.jetbrains_ides) > 0
|
||||
error_message = "The jetbrains_ides must not be empty."
|
||||
}
|
||||
#ccheck if the list contains duplicates
|
||||
# check if the list contains duplicates
|
||||
validation {
|
||||
condition = length(var.jetbrains_ides) == length(toset(var.jetbrains_ides))
|
||||
error_message = "The jetbrains_ides must not contain duplicates."
|
||||
@@ -120,7 +120,7 @@ data "coder_parameter" "jetbrains_ide" {
|
||||
icon = "/icon/gateway.svg"
|
||||
mutable = true
|
||||
# check if default is in the jet_brains_ides list and if it is not empty or null otherwise set it to null
|
||||
default = var.default != null && var.default != "" && contains(var.jetbrains_ides, var.default) ? local.jetbrains_ides[var.default].value : null
|
||||
default = var.default != null && var.default != "" && contains(var.jetbrains_ides, var.default) ? local.jetbrains_ides[var.default].value : local.jetbrains_ides[var.jetbrains_ides[0]].value
|
||||
|
||||
dynamic "option" {
|
||||
for_each = { for key, value in local.jetbrains_ides : key => value if contains(var.jetbrains_ides, key) }
|
||||
@@ -146,7 +146,7 @@ resource "coder_app" "gateway" {
|
||||
"&agent=",
|
||||
var.agent_name,
|
||||
"&folder=",
|
||||
var.project_directory,
|
||||
var.folder,
|
||||
"&url=",
|
||||
data.coder_workspace.me.access_url,
|
||||
"&token=",
|
||||
@@ -156,7 +156,7 @@ resource "coder_app" "gateway" {
|
||||
"&ide_build_number=",
|
||||
jsondecode(data.coder_parameter.jetbrains_ide.value)[1],
|
||||
"&ide_download_link=",
|
||||
jsondecode(data.coder_parameter.jetbrains_ide.value)[2]
|
||||
jsondecode(data.coder_parameter.jetbrains_ide.value)[2],
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user