diff --git a/aws-region/main.test.ts b/aws-region/main.test.ts index 42433df..0693e65 100644 --- a/aws-region/main.test.ts +++ b/aws-region/main.test.ts @@ -22,4 +22,13 @@ describe("aws-region", async () => { }); expect(state.outputs.value.value).toBe("us-west-2"); }); + + it("set custom order for coder_parameter", async () => { + const order = 99; + const state = await runTerraformApply(import.meta.dir, { + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(1); + expect(state.resources[0].instances[0].attributes.order).toBe(order); + }); }); diff --git a/aws-region/main.tf b/aws-region/main.tf index 7594320..12a01fe 100644 --- a/aws-region/main.tf +++ b/aws-region/main.tf @@ -51,6 +51,12 @@ variable "exclude" { type = list(string) } +variable "coder_parameter_order" { + type = number + 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)." + default = null +} + locals { # This is a static list because the regions don't change _that_ # frequently and including the `aws_regions` data source requires @@ -176,6 +182,7 @@ data "coder_parameter" "region" { display_name = var.display_name description = var.description default = var.default == "" ? null : var.default + order = var.coder_parameter_order mutable = var.mutable dynamic "option" { for_each = { for k, v in local.regions : k => v if !(contains(var.exclude, k)) } diff --git a/azure-region/main.test.ts b/azure-region/main.test.ts index 0e41e29..bebc0c9 100644 --- a/azure-region/main.test.ts +++ b/azure-region/main.test.ts @@ -22,4 +22,13 @@ describe("azure-region", async () => { }); expect(state.outputs.value.value).toBe("westus"); }); + + it("set custom order for coder_parameter", async () => { + const order = 99; + const state = await runTerraformApply(import.meta.dir, { + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(1); + expect(state.resources[0].instances[0].attributes.order).toBe(order); + }); }); diff --git a/azure-region/main.tf b/azure-region/main.tf index 307d61d..3d1c2f1 100644 --- a/azure-region/main.tf +++ b/azure-region/main.tf @@ -50,6 +50,12 @@ variable "exclude" { type = list(string) } +variable "coder_parameter_order" { + type = number + 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)." + default = null +} + locals { # Note: Options are limited to 64 regions, some redundant regions have been removed. all_regions = { @@ -309,6 +315,7 @@ data "coder_parameter" "region" { display_name = var.display_name description = var.description default = var.default == "" ? null : var.default + order = var.coder_parameter_order mutable = var.mutable icon = "/icon/azure.png" dynamic "option" { diff --git a/dotfiles/main.test.ts b/dotfiles/main.test.ts index 175690f..6026719 100644 --- a/dotfiles/main.test.ts +++ b/dotfiles/main.test.ts @@ -27,4 +27,14 @@ describe("dotfiles", async () => { }); expect(state.outputs.dotfiles_uri.value).toBe(default_dotfiles_uri); }); + + it("set custom order for coder_parameter", async () => { + const order = 99; + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(2); + expect(state.resources[0].instances[0].attributes.order).toBe(order); + }); }); diff --git a/dotfiles/main.tf b/dotfiles/main.tf index 12ca826..cf21864 100644 --- a/dotfiles/main.tf +++ b/dotfiles/main.tf @@ -20,10 +20,17 @@ variable "default_dotfiles_uri" { default = "" } +variable "coder_parameter_order" { + type = number + 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)." + default = null +} + data "coder_parameter" "dotfiles_uri" { type = "string" name = "dotfiles_uri" display_name = "Dotfiles URL (optional)" + order = var.coder_parameter_order default = var.default_dotfiles_uri description = "Enter a URL for a [dotfiles repository](https://dotfiles.github.io) to personalize your workspace" mutable = true diff --git a/exoscale-instance-type/main.test.ts b/exoscale-instance-type/main.test.ts index eeb6745..e4b998b 100644 --- a/exoscale-instance-type/main.test.ts +++ b/exoscale-instance-type/main.test.ts @@ -31,4 +31,13 @@ describe("exoscale-instance-type", async () => { }); }).toThrow('default value "gpu3.huge" must be defined as one of options'); }); + + it("set custom order for coder_parameter", async () => { + const order = 99; + const state = await runTerraformApply(import.meta.dir, { + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(1); + expect(state.resources[0].instances[0].attributes.order).toBe(order); + }); }); diff --git a/exoscale-instance-type/main.tf b/exoscale-instance-type/main.tf index f7c8998..65d3729 100644 --- a/exoscale-instance-type/main.tf +++ b/exoscale-instance-type/main.tf @@ -56,6 +56,12 @@ variable "exclude" { type = list(string) } +variable "coder_parameter_order" { + type = number + 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)." + default = null +} + locals { # https://www.exoscale.com/pricing/ @@ -257,6 +263,7 @@ data "coder_parameter" "instance_type" { display_name = var.display_name description = var.description default = var.default == "" ? null : var.default + order = var.coder_parameter_order mutable = var.mutable dynamic "option" { for_each = [for k, v in concat( diff --git a/exoscale-zone/main.test.ts b/exoscale-zone/main.test.ts index 7c423e7..ca8eeb7 100644 --- a/exoscale-zone/main.test.ts +++ b/exoscale-zone/main.test.ts @@ -22,4 +22,13 @@ describe("exoscale-zone", async () => { }); expect(state.outputs.value.value).toBe("at-vie-1"); }); + + it("set custom order for coder_parameter", async () => { + const order = 99; + const state = await runTerraformApply(import.meta.dir, { + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(1); + expect(state.resources[0].instances[0].attributes.order).toBe(order); + }); }); diff --git a/exoscale-zone/main.tf b/exoscale-zone/main.tf index 01f1467..090acb4 100644 --- a/exoscale-zone/main.tf +++ b/exoscale-zone/main.tf @@ -51,6 +51,11 @@ variable "exclude" { type = list(string) } +variable "coder_parameter_order" { + type = number + 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)." + default = null +} locals { # This is a static list because the zones don't change _that_ @@ -94,6 +99,7 @@ data "coder_parameter" "zone" { display_name = var.display_name description = var.description default = var.default == "" ? null : var.default + order = var.coder_parameter_order mutable = var.mutable dynamic "option" { for_each = { for k, v in local.zones : k => v if !(contains(var.exclude, k)) } diff --git a/gcp-region/main.test.ts b/gcp-region/main.test.ts index 2ec623b..bf01c2b 100644 --- a/gcp-region/main.test.ts +++ b/gcp-region/main.test.ts @@ -40,4 +40,13 @@ describe("gcp-region", async () => { }); expect(state.outputs.value.value).toBe("us-west2-b"); }); + + it("set custom order for coder_parameter", async () => { + const order = 99; + const state = await runTerraformApply(import.meta.dir, { + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(1); + expect(state.resources[0].instances[0].attributes.order).toBe(order); + }); }); diff --git a/gcp-region/main.tf b/gcp-region/main.tf index e9f549d..0a75924 100644 --- a/gcp-region/main.tf +++ b/gcp-region/main.tf @@ -63,6 +63,12 @@ variable "single_zone_per_region" { type = bool } +variable "coder_parameter_order" { + type = number + 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)." + default = null +} + locals { zones = { # US Central @@ -715,6 +721,7 @@ data "coder_parameter" "region" { icon = "/icon/gcp.png" mutable = var.mutable default = var.default != null && var.default != "" && (!var.gpu_only || try(local.zones[var.default].gpu, false)) ? var.default : null + order = var.coder_parameter_order dynamic "option" { for_each = { for k, v in local.zones : k => v diff --git a/git-config/main.test.ts b/git-config/main.test.ts index 1241956..fe410aa 100644 --- a/git-config/main.test.ts +++ b/git-config/main.test.ts @@ -66,4 +66,34 @@ describe("git-config", async () => { { type: "coder_env", name: "git_commmiter_name" }, ]); }); + + it("set custom order for coder_parameter for both fields", async () => { + const order = 20; + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + allow_username_change: "true", + allow_email_change: "true", + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(5); + // user_email order is the same as the order + expect(state.resources[0].instances[0].attributes.order).toBe(order); + // username order is incremented by 1 + // @ts-ignore: Object is possibly 'null'. + expect(state.resources[1].instances[0]?.attributes.order).toBe(order + 1); + }); + + it("set custom order for coder_parameter for just username", async () => { + const order = 30; + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + allow_email_change: "false", + allow_username_change: "true", + coder_parameter_order: order.toString(), + }); + expect(state.resources).toHaveLength(4); + // user_email was not created + // username order is incremented by 1 + expect(state.resources[0].instances[0].attributes.order).toBe(order + 1); + }); }); diff --git a/git-config/main.tf b/git-config/main.tf index a0e96ad..fe19288 100644 --- a/git-config/main.tf +++ b/git-config/main.tf @@ -26,6 +26,11 @@ variable "allow_email_change" { default = false } +variable "coder_parameter_order" { + type = number + 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)." + default = null +} data "coder_workspace" "me" {} @@ -34,6 +39,7 @@ data "coder_parameter" "user_email" { name = "user_email" type = "string" default = "" + order = var.coder_parameter_order != null ? var.coder_parameter_order + 0 : null description = "Git user.email to be used for commits. Leave empty to default to Coder user's email." display_name = "Git config user.email" mutable = true @@ -44,6 +50,7 @@ data "coder_parameter" "username" { name = "username" type = "string" default = "" + order = var.coder_parameter_order != null ? var.coder_parameter_order + 1 : null description = "Git user.name to be used for commits. Leave empty to default to Coder user's Full Name." display_name = "Full Name for Git config" mutable = true