From 3f8d4566933ce65a37024384cf6787a912da5f63 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Thu, 11 Apr 2024 09:58:37 -0700 Subject: [PATCH 1/3] feat: add coder_parameter_order --- aws-region/main.test.ts | 9 +++++++++ aws-region/main.tf | 7 +++++++ azure-region/main.test.ts | 9 +++++++++ azure-region/main.tf | 7 +++++++ dotfiles/main.test.ts | 10 ++++++++++ dotfiles/main.tf | 7 +++++++ exoscale-instance-type/main.test.ts | 9 +++++++++ exoscale-instance-type/main.tf | 7 +++++++ exoscale-zone/main.test.ts | 9 +++++++++ exoscale-zone/main.tf | 6 ++++++ gcp-region/main.test.ts | 9 +++++++++ gcp-region/main.tf | 7 +++++++ 12 files changed, 96 insertions(+) diff --git a/aws-region/main.test.ts b/aws-region/main.test.ts index 42433df3..0693e65a 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 75943206..12a01fe7 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 0e41e297..bebc0c9f 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 307d61d4..3d1c2f13 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 69eda321..a075a27f 100644 --- a/dotfiles/main.test.ts +++ b/dotfiles/main.test.ts @@ -18,4 +18,14 @@ describe("dotfiles", async () => { }); expect(state.outputs.dotfiles_uri.value).toBe(""); }); + + 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 c0b01357..3e19fb98 100644 --- a/dotfiles/main.tf +++ b/dotfiles/main.tf @@ -14,11 +14,18 @@ variable "agent_id" { description = "The ID of a Coder agent." } +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)" default = "" + order = var.coder_parameter_order description = "Enter a URL for a [dotfiles repository](https://dotfiles.github.io) to personalize your workspace" mutable = true icon = "/icon/dotfiles.svg" diff --git a/exoscale-instance-type/main.test.ts b/exoscale-instance-type/main.test.ts index eeb6745f..e4b998bc 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 f7c89980..65d37291 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 7c423e76..ca8eeb72 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 01f1467e..090acb4c 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 2ec623b7..bf01c2bc 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 e9f549de..0a759248 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 From 8452de121ed3146409d0f218ff7626dc0464f4df Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Thu, 11 Apr 2024 15:43:33 -0700 Subject: [PATCH 2/3] feat(git-clone): add coder_parameter order variables --- git-config/main.tf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/git-config/main.tf b/git-config/main.tf index d92a0b7e..050df616 100644 --- a/git-config/main.tf +++ b/git-config/main.tf @@ -26,6 +26,17 @@ variable "allow_email_change" { default = false } +variable "coder_parameter_user_email_order" { + type = number + description = "The order determines the position of the 'user_email' 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 +} + +variable "coder_parameter_username_order" { + type = number + description = "The order determines the position of the 'username' 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 +45,7 @@ data "coder_parameter" "user_email" { name = "user_email" type = "string" default = "" + order = var.coder_parameter_user_email_order 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 +56,7 @@ data "coder_parameter" "username" { name = "username" type = "string" default = "" + order = var.coder_parameter_username_order 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 From 6c942977e6f05d5d8cac56f7890496aca3957fd3 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Mon, 15 Apr 2024 08:14:50 -0700 Subject: [PATCH 3/3] feat: use just a single coder_parameter_order for the group --- git-config/main.test.ts | 30 ++++++++++++++++++++++++++++++ git-config/main.tf | 14 ++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/git-config/main.test.ts b/git-config/main.test.ts index 1241956e..fe410aa3 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 2b9544ad..fe192886 100644 --- a/git-config/main.tf +++ b/git-config/main.tf @@ -26,15 +26,9 @@ variable "allow_email_change" { default = false } -variable "coder_parameter_user_email_order" { +variable "coder_parameter_order" { type = number - description = "The order determines the position of the 'user_email' 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 -} - -variable "coder_parameter_username_order" { - type = number - description = "The order determines the position of the 'username' template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)." + 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 } @@ -45,7 +39,7 @@ data "coder_parameter" "user_email" { name = "user_email" type = "string" default = "" - order = var.coder_parameter_user_email_order + 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 @@ -56,7 +50,7 @@ data "coder_parameter" "username" { name = "username" type = "string" default = "" - order = var.coder_parameter_username_order + 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