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

Commit 2c94c82

Browse files
authored
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.
1 parent e1f4e25 commit 2c94c82

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

aws-region/main.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("aws-region", async () => {
1313

1414
it("default output", async () => {
1515
const state = await runTerraformApply(import.meta.dir, {});
16-
expect(state.outputs.value.value).toBe("us-east-1");
16+
expect(state.outputs.value.value).toBe("");
1717
});
1818

1919
it("customized default", async () => {

aws-region/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ variable "description" {
2222
}
2323

2424
variable "default" {
25-
default = "us-east-1"
25+
default = ""
2626
description = "The default region to use if no region is specified."
2727
type = string
2828
}
@@ -131,7 +131,7 @@ data "coder_parameter" "region" {
131131
name = "aws_region"
132132
display_name = var.display_name
133133
description = var.description
134-
default = var.default
134+
default = var.default == "" ? null : var.default
135135
mutable = var.mutable
136136
dynamic "option" {
137137
for_each = { for k, v in local.regions : k => v if !(contains(var.exclude, k)) }

azure-region/main.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("azure-region", async () => {
1313

1414
it("default output", async () => {
1515
const state = await runTerraformApply(import.meta.dir, {});
16-
expect(state.outputs.value.value).toBe("eastus");
16+
expect(state.outputs.value.value).toBe("");
1717
});
1818

1919
it("customized default", async () => {

azure-region/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ variable "description" {
2121
}
2222

2323
variable "default" {
24-
default = "eastus"
24+
default = ""
2525
description = "The default region to use if no region is specified."
2626
type = string
2727
}
@@ -308,7 +308,7 @@ data "coder_parameter" "region" {
308308
name = "azure_region"
309309
display_name = var.display_name
310310
description = var.description
311-
default = var.default
311+
default = var.default == "" ? null : var.default
312312
mutable = var.mutable
313313
icon = "/icon/azure.png"
314314
dynamic "option" {

jetbrains-gateway/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ This module adds a JetBrains Gateway Button to open any workspace with a single
1313

1414
```hcl
1515
module "jetbrains_gateway" {
16-
source = "https://registry.coder.com/modules/jetbrains-gateway"
17-
agent_id = coder_agent.example.id
18-
agent_name = "example"
19-
project_directory = "/home/coder/example"
20-
jetbrains_ides = ["GO", "WS", "IU", "IC", "PY", "PC", "PS", "CL", "RM", "DB", "RD"]
16+
source = "https://registry.coder.com/modules/jetbrains-gateway"
17+
agent_id = coder_agent.example.id
18+
agent_name = "example"
19+
folder = "/home/coder/example"
20+
jetbrains_ides = ["GO", "WS", "IU", "IC", "PY", "PC", "PS", "CL", "RM", "DB", "RD"]
2121
}
2222
```
2323

@@ -29,12 +29,12 @@ module "jetbrains_gateway" {
2929

3030
```hcl
3131
module "jetbrains_gateway" {
32-
source = "https://registry.coder.com/modules/jetbrains-gateway"
33-
agent_id = coder_agent.example.id
34-
agent_name = "example"
35-
project_directory = "/home/coder/example"
36-
jetbrains_ides = ["GO", "WS"]
37-
default = "GO"
32+
source = "https://registry.coder.com/modules/jetbrains-gateway"
33+
agent_id = coder_agent.example.id
34+
agent_name = "example"
35+
folder = "/home/coder/example"
36+
jetbrains_ides = ["GO", "WS"]
37+
default = "GO"
3838
}
3939
```
4040

jetbrains-gateway/main.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe } from "bun:test";
2+
import {
3+
runTerraformInit,
4+
testRequiredVariables,
5+
} from "../test";
6+
7+
describe("jetbrains-gateway`", async () => {
8+
await runTerraformInit(import.meta.dir);
9+
10+
await testRequiredVariables(import.meta.dir, {
11+
agent_id: "foo",
12+
agent_name: "bar",
13+
folder: "/baz/",
14+
jetbrains_ides: '["IU", "IC", "PY"]',
15+
});
16+
});

jetbrains-gateway/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ variable "agent_name" {
1919
description = "The name of a Coder agent."
2020
}
2121

22-
variable "project_directory" {
22+
variable "folder" {
2323
type = string
2424
description = "The directory to open in the IDE. e.g. /home/coder/project"
2525
}
2626

2727
variable "default" {
28-
default = null
28+
default = ""
2929
type = string
3030
description = "Default IDE"
3131
}
@@ -46,7 +46,7 @@ variable "jetbrains_ides" {
4646
condition = length(var.jetbrains_ides) > 0
4747
error_message = "The jetbrains_ides must not be empty."
4848
}
49-
#ccheck if the list contains duplicates
49+
# check if the list contains duplicates
5050
validation {
5151
condition = length(var.jetbrains_ides) == length(toset(var.jetbrains_ides))
5252
error_message = "The jetbrains_ides must not contain duplicates."
@@ -120,7 +120,7 @@ data "coder_parameter" "jetbrains_ide" {
120120
icon = "/icon/gateway.svg"
121121
mutable = true
122122
# check if default is in the jet_brains_ides list and if it is not empty or null otherwise set it to null
123-
default = var.default != null && var.default != "" && contains(var.jetbrains_ides, var.default) ? local.jetbrains_ides[var.default].value : null
123+
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
124124

125125
dynamic "option" {
126126
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" {
146146
"&agent=",
147147
var.agent_name,
148148
"&folder=",
149-
var.project_directory,
149+
var.folder,
150150
"&url=",
151151
data.coder_workspace.me.access_url,
152152
"&token=",
@@ -156,7 +156,7 @@ resource "coder_app" "gateway" {
156156
"&ide_build_number=",
157157
jsondecode(data.coder_parameter.jetbrains_ide.value)[1],
158158
"&ide_download_link=",
159-
jsondecode(data.coder_parameter.jetbrains_ide.value)[2]
159+
jsondecode(data.coder_parameter.jetbrains_ide.value)[2],
160160
])
161161
}
162162

0 commit comments

Comments
 (0)