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

Commit a8c659a

Browse files
feat: add coder_parameter_order to all data.coder_parameter fields (#223)
1 parent c4df384 commit a8c659a

File tree

14 files changed

+133
-0
lines changed

14 files changed

+133
-0
lines changed

aws-region/main.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@ describe("aws-region", async () => {
2222
});
2323
expect(state.outputs.value.value).toBe("us-west-2");
2424
});
25+
26+
it("set custom order for coder_parameter", async () => {
27+
const order = 99;
28+
const state = await runTerraformApply(import.meta.dir, {
29+
coder_parameter_order: order.toString(),
30+
});
31+
expect(state.resources).toHaveLength(1);
32+
expect(state.resources[0].instances[0].attributes.order).toBe(order);
33+
});
2534
});

aws-region/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ variable "exclude" {
5151
type = list(string)
5252
}
5353

54+
variable "coder_parameter_order" {
55+
type = number
56+
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
57+
default = null
58+
}
59+
5460
locals {
5561
# This is a static list because the regions don't change _that_
5662
# frequently and including the `aws_regions` data source requires
@@ -176,6 +182,7 @@ data "coder_parameter" "region" {
176182
display_name = var.display_name
177183
description = var.description
178184
default = var.default == "" ? null : var.default
185+
order = var.coder_parameter_order
179186
mutable = var.mutable
180187
dynamic "option" {
181188
for_each = { for k, v in local.regions : k => v if !(contains(var.exclude, k)) }

azure-region/main.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@ describe("azure-region", async () => {
2222
});
2323
expect(state.outputs.value.value).toBe("westus");
2424
});
25+
26+
it("set custom order for coder_parameter", async () => {
27+
const order = 99;
28+
const state = await runTerraformApply(import.meta.dir, {
29+
coder_parameter_order: order.toString(),
30+
});
31+
expect(state.resources).toHaveLength(1);
32+
expect(state.resources[0].instances[0].attributes.order).toBe(order);
33+
});
2534
});

azure-region/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ variable "exclude" {
5050
type = list(string)
5151
}
5252

53+
variable "coder_parameter_order" {
54+
type = number
55+
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
56+
default = null
57+
}
58+
5359
locals {
5460
# Note: Options are limited to 64 regions, some redundant regions have been removed.
5561
all_regions = {
@@ -309,6 +315,7 @@ data "coder_parameter" "region" {
309315
display_name = var.display_name
310316
description = var.description
311317
default = var.default == "" ? null : var.default
318+
order = var.coder_parameter_order
312319
mutable = var.mutable
313320
icon = "/icon/azure.png"
314321
dynamic "option" {

dotfiles/main.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ describe("dotfiles", async () => {
2727
});
2828
expect(state.outputs.dotfiles_uri.value).toBe(default_dotfiles_uri);
2929
});
30+
31+
it("set custom order for coder_parameter", async () => {
32+
const order = 99;
33+
const state = await runTerraformApply(import.meta.dir, {
34+
agent_id: "foo",
35+
coder_parameter_order: order.toString(),
36+
});
37+
expect(state.resources).toHaveLength(2);
38+
expect(state.resources[0].instances[0].attributes.order).toBe(order);
39+
});
3040
});

dotfiles/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ variable "default_dotfiles_uri" {
2020
default = ""
2121
}
2222

23+
variable "coder_parameter_order" {
24+
type = number
25+
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
26+
default = null
27+
}
28+
2329
data "coder_parameter" "dotfiles_uri" {
2430
type = "string"
2531
name = "dotfiles_uri"
2632
display_name = "Dotfiles URL (optional)"
33+
order = var.coder_parameter_order
2734
default = var.default_dotfiles_uri
2835
description = "Enter a URL for a [dotfiles repository](https://dotfiles.github.io) to personalize your workspace"
2936
mutable = true

exoscale-instance-type/main.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,13 @@ describe("exoscale-instance-type", async () => {
3131
});
3232
}).toThrow('default value "gpu3.huge" must be defined as one of options');
3333
});
34+
35+
it("set custom order for coder_parameter", async () => {
36+
const order = 99;
37+
const state = await runTerraformApply(import.meta.dir, {
38+
coder_parameter_order: order.toString(),
39+
});
40+
expect(state.resources).toHaveLength(1);
41+
expect(state.resources[0].instances[0].attributes.order).toBe(order);
42+
});
3443
});

exoscale-instance-type/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ variable "exclude" {
5656
type = list(string)
5757
}
5858

59+
variable "coder_parameter_order" {
60+
type = number
61+
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
62+
default = null
63+
}
64+
5965
locals {
6066
# https://www.exoscale.com/pricing/
6167

@@ -257,6 +263,7 @@ data "coder_parameter" "instance_type" {
257263
display_name = var.display_name
258264
description = var.description
259265
default = var.default == "" ? null : var.default
266+
order = var.coder_parameter_order
260267
mutable = var.mutable
261268
dynamic "option" {
262269
for_each = [for k, v in concat(

exoscale-zone/main.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@ describe("exoscale-zone", async () => {
2222
});
2323
expect(state.outputs.value.value).toBe("at-vie-1");
2424
});
25+
26+
it("set custom order for coder_parameter", async () => {
27+
const order = 99;
28+
const state = await runTerraformApply(import.meta.dir, {
29+
coder_parameter_order: order.toString(),
30+
});
31+
expect(state.resources).toHaveLength(1);
32+
expect(state.resources[0].instances[0].attributes.order).toBe(order);
33+
});
2534
});

exoscale-zone/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ variable "exclude" {
5151
type = list(string)
5252
}
5353

54+
variable "coder_parameter_order" {
55+
type = number
56+
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
57+
default = null
58+
}
5459

5560
locals {
5661
# This is a static list because the zones don't change _that_
@@ -94,6 +99,7 @@ data "coder_parameter" "zone" {
9499
display_name = var.display_name
95100
description = var.description
96101
default = var.default == "" ? null : var.default
102+
order = var.coder_parameter_order
97103
mutable = var.mutable
98104
dynamic "option" {
99105
for_each = { for k, v in local.zones : k => v if !(contains(var.exclude, k)) }

gcp-region/main.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,13 @@ describe("gcp-region", async () => {
4040
});
4141
expect(state.outputs.value.value).toBe("us-west2-b");
4242
});
43+
44+
it("set custom order for coder_parameter", async () => {
45+
const order = 99;
46+
const state = await runTerraformApply(import.meta.dir, {
47+
coder_parameter_order: order.toString(),
48+
});
49+
expect(state.resources).toHaveLength(1);
50+
expect(state.resources[0].instances[0].attributes.order).toBe(order);
51+
});
4352
});

gcp-region/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ variable "single_zone_per_region" {
6363
type = bool
6464
}
6565

66+
variable "coder_parameter_order" {
67+
type = number
68+
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
69+
default = null
70+
}
71+
6672
locals {
6773
zones = {
6874
# US Central
@@ -715,6 +721,7 @@ data "coder_parameter" "region" {
715721
icon = "/icon/gcp.png"
716722
mutable = var.mutable
717723
default = var.default != null && var.default != "" && (!var.gpu_only || try(local.zones[var.default].gpu, false)) ? var.default : null
724+
order = var.coder_parameter_order
718725
dynamic "option" {
719726
for_each = {
720727
for k, v in local.zones : k => v

git-config/main.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,34 @@ describe("git-config", async () => {
6666
{ type: "coder_env", name: "git_commmiter_name" },
6767
]);
6868
});
69+
70+
it("set custom order for coder_parameter for both fields", async () => {
71+
const order = 20;
72+
const state = await runTerraformApply(import.meta.dir, {
73+
agent_id: "foo",
74+
allow_username_change: "true",
75+
allow_email_change: "true",
76+
coder_parameter_order: order.toString(),
77+
});
78+
expect(state.resources).toHaveLength(5);
79+
// user_email order is the same as the order
80+
expect(state.resources[0].instances[0].attributes.order).toBe(order);
81+
// username order is incremented by 1
82+
// @ts-ignore: Object is possibly 'null'.
83+
expect(state.resources[1].instances[0]?.attributes.order).toBe(order + 1);
84+
});
85+
86+
it("set custom order for coder_parameter for just username", async () => {
87+
const order = 30;
88+
const state = await runTerraformApply(import.meta.dir, {
89+
agent_id: "foo",
90+
allow_email_change: "false",
91+
allow_username_change: "true",
92+
coder_parameter_order: order.toString(),
93+
});
94+
expect(state.resources).toHaveLength(4);
95+
// user_email was not created
96+
// username order is incremented by 1
97+
expect(state.resources[0].instances[0].attributes.order).toBe(order + 1);
98+
});
6999
});

git-config/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ variable "allow_email_change" {
2626
default = false
2727
}
2828

29+
variable "coder_parameter_order" {
30+
type = number
31+
description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
32+
default = null
33+
}
2934

3035
data "coder_workspace" "me" {}
3136

@@ -34,6 +39,7 @@ data "coder_parameter" "user_email" {
3439
name = "user_email"
3540
type = "string"
3641
default = ""
42+
order = var.coder_parameter_order != null ? var.coder_parameter_order + 0 : null
3743
description = "Git user.email to be used for commits. Leave empty to default to Coder user's email."
3844
display_name = "Git config user.email"
3945
mutable = true
@@ -44,6 +50,7 @@ data "coder_parameter" "username" {
4450
name = "username"
4551
type = "string"
4652
default = ""
53+
order = var.coder_parameter_order != null ? var.coder_parameter_order + 1 : null
4754
description = "Git user.name to be used for commits. Leave empty to default to Coder user's Full Name."
4855
display_name = "Full Name for Git config"
4956
mutable = true

0 commit comments

Comments
 (0)