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 2b9544a..fe19288 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