From d81eec6b6eec9771d5561d3d071da6e7571604fb Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 27 Jun 2023 11:36:06 +0200 Subject: [PATCH 1/5] feat: add priority to coder_parameter --- docs/data-sources/git_auth.md | 2 -- docs/data-sources/parameter.md | 3 +-- docs/data-sources/provisioner.md | 2 -- docs/data-sources/workspace.md | 2 -- docs/resources/agent.md | 2 -- docs/resources/agent_instance.md | 2 -- docs/resources/app.md | 2 -- docs/resources/metadata.md | 2 -- examples/resources/coder_parameter/resource.tf | 16 +++++++++------- provider/parameter.go | 9 +++++++++ 10 files changed, 19 insertions(+), 23 deletions(-) diff --git a/docs/data-sources/git_auth.md b/docs/data-sources/git_auth.md index 5573993d..53e01981 100644 --- a/docs/data-sources/git_auth.md +++ b/docs/data-sources/git_auth.md @@ -46,5 +46,3 @@ EOF ### Read-Only - `access_token` (String) The access token returned by the git authentication provider. This can be used to pre-authenticate command-line tools. - - diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index ef2e407c..8e434381 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -29,6 +29,7 @@ Use this data source to configure editable options for workspaces. - `legacy_variable_name` (String, Deprecated) Name of the legacy Terraform variable. Coder will use it to lookup the variable value. - `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution! - `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option)) +- `priority` (Number) The priority of template parameters determines their position ahead of parameters with lower priorities in the UI/CLI presentation. - `type` (String) The type of this parameter. Must be one of: "number", "string", "bool", or "list(string)". - `validation` (Block List, Max: 1) Validate the input of a parameter. (see [below for nested schema](#nestedblock--validation)) @@ -67,5 +68,3 @@ Read-Only: - `max_disabled` (Boolean) Helper field to check if max is present - `min_disabled` (Boolean) Helper field to check if min is present - - diff --git a/docs/data-sources/provisioner.md b/docs/data-sources/provisioner.md index 47bdaf04..4316aeea 100644 --- a/docs/data-sources/provisioner.md +++ b/docs/data-sources/provisioner.md @@ -20,5 +20,3 @@ Use this data source to get information about the Coder provisioner. - `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants). - `id` (String) The ID of this resource. - `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants). - - diff --git a/docs/data-sources/workspace.md b/docs/data-sources/workspace.md index ffe49eb8..e7d58a5d 100644 --- a/docs/data-sources/workspace.md +++ b/docs/data-sources/workspace.md @@ -37,5 +37,3 @@ resource "kubernetes_pod" "dev" { - `owner_session_token` (String) Session token for interfacing with a Coder deployment. It is regenerated everytime a workspace is started. - `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1. - `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count". - - diff --git a/docs/resources/agent.md b/docs/resources/agent.md index f3690194..d073f7c5 100644 --- a/docs/resources/agent.md +++ b/docs/resources/agent.md @@ -79,5 +79,3 @@ Optional: - `display_name` (String) The user-facing name of this value. - `timeout` (Number) The maximum time the command is allowed to run in seconds. - - diff --git a/docs/resources/agent_instance.md b/docs/resources/agent_instance.md index 7eab0dde..fa8574fa 100644 --- a/docs/resources/agent_instance.md +++ b/docs/resources/agent_instance.md @@ -40,5 +40,3 @@ resource "coder_agent_instance" "dev" { ### Read-Only - `id` (String) The ID of this resource. - - diff --git a/docs/resources/app.md b/docs/resources/app.md index e120f658..7b70bf6a 100644 --- a/docs/resources/app.md +++ b/docs/resources/app.md @@ -90,5 +90,3 @@ Required: - `interval` (Number) Duration in seconds to wait between healthcheck requests. - `threshold` (Number) Number of consecutive heathcheck failures before returning an unhealthy status. - `url` (String) HTTP address used determine the application readiness. A successful health check is a HTTP response code less than 500 returned before healthcheck.interval seconds. - - diff --git a/docs/resources/metadata.md b/docs/resources/metadata.md index 6edcd1d0..2d67e526 100644 --- a/docs/resources/metadata.md +++ b/docs/resources/metadata.md @@ -80,5 +80,3 @@ Optional: Read-Only: - `is_null` (Boolean) - - diff --git a/examples/resources/coder_parameter/resource.tf b/examples/resources/coder_parameter/resource.tf index a89ce1b8..d40ca2f2 100644 --- a/examples/resources/coder_parameter/resource.tf +++ b/examples/resources/coder_parameter/resource.tf @@ -41,16 +41,18 @@ data "coder_parameter" "is_public_instance" { } data "coder_parameter" "cores" { - name = "CPU Cores" - type = "number" - icon = "/icon/cpu.svg" - default = 3 + name = "CPU Cores" + type = "number" + icon = "/icon/cpu.svg" + default = 3 + priority = 10 } data "coder_parameter" "disk_size" { - name = "Disk Size" - type = "number" - default = "5" + name = "Disk Size" + type = "number" + default = "5" + priority = 8 validation { # This can apply to number. min = 0 diff --git a/provider/parameter.go b/provider/parameter.go index 7bb4c465..ce855737 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -57,6 +57,8 @@ type Parameter struct { Validation []Validation Optional bool + Priority int + LegacyVariableName string `mapstructure:"legacy_variable_name"` LegacyVariable string `mapstructure:"legacy_variable"` } @@ -90,6 +92,7 @@ func parameterDataSource() *schema.Resource { Option interface{} Validation interface{} Optional interface{} + Priority interface{} LegacyVariableName interface{} LegacyVariable interface{} @@ -122,6 +125,7 @@ func parameterDataSource() *schema.Resource { rd.Set("optional", val) return val }(), + Priority: rd.Get("priority"), LegacyVariableName: rd.Get("legacy_variable_name"), LegacyVariable: rd.Get("legacy_variable"), }, ¶meter) @@ -331,6 +335,11 @@ func parameterDataSource() *schema.Resource { Computed: true, Description: "Whether this value is optional.", }, + "priority": { + Type: schema.TypeInt, + Optional: true, + Description: "The priority of template parameters determines their position ahead of parameters with lower priorities in the UI/CLI presentation.", + }, "legacy_variable_name": { Type: schema.TypeString, Optional: true, From 03ddcbb32630ed7e5260e61199f03a9ca16a8cc6 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 27 Jun 2023 13:34:52 +0200 Subject: [PATCH 2/5] Improve messaging --- docs/data-sources/parameter.md | 2 +- provider/parameter.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index 8e434381..b6b0fbe9 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -29,7 +29,7 @@ Use this data source to configure editable options for workspaces. - `legacy_variable_name` (String, Deprecated) Name of the legacy Terraform variable. Coder will use it to lookup the variable value. - `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution! - `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option)) -- `priority` (Number) The priority of template parameters determines their position ahead of parameters with lower priorities in the UI/CLI presentation. +- `priority` (Number) The priority of a template parameter determines its position in the UI/CLI presentation. A higher priority parameter is positioned ahead of a lower priority one and parameters with the same priority are ordered by name in ascending order. - `type` (String) The type of this parameter. Must be one of: "number", "string", "bool", or "list(string)". - `validation` (Block List, Max: 1) Validate the input of a parameter. (see [below for nested schema](#nestedblock--validation)) diff --git a/provider/parameter.go b/provider/parameter.go index ce855737..5e2dbca0 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -338,7 +338,7 @@ func parameterDataSource() *schema.Resource { "priority": { Type: schema.TypeInt, Optional: true, - Description: "The priority of template parameters determines their position ahead of parameters with lower priorities in the UI/CLI presentation.", + Description: "The priority of a template parameter determines its position in the UI/CLI presentation. A higher priority parameter is positioned ahead of a lower priority one and parameters with the same priority are ordered by name in ascending order.", }, "legacy_variable_name": { Type: schema.TypeString, From 6b46d6120a4f8baaf3d16a6078931d844e5f3c63 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 27 Jun 2023 13:37:27 +0200 Subject: [PATCH 3/5] basic test --- provider/parameter_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/provider/parameter_test.go b/provider/parameter_test.go index d749592b..cff61c00 100644 --- a/provider/parameter_test.go +++ b/provider/parameter_test.go @@ -43,6 +43,7 @@ func TestParameter(t *testing.T) { icon = "/icon/east.svg" description = "Select for east!" } + priority = 5 } `, Check: func(state *terraform.ResourceState) { @@ -62,6 +63,7 @@ func TestParameter(t *testing.T) { "option.1.value": "us-east1-a", "option.1.icon": "/icon/east.svg", "option.1.description": "Select for east!", + "priority": "5", } { require.Equal(t, value, attrs[key]) } From 58dd781f00c196593f5c3cc28a899d15bc9b4472 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 28 Jun 2023 15:02:18 +0200 Subject: [PATCH 4/5] s/priority/order/g --- docs/data-sources/parameter.md | 2 +- examples/resources/coder_parameter/resource.tf | 18 +++++++++--------- provider/parameter.go | 10 +++++----- provider/parameter_test.go | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index b6b0fbe9..59723a6a 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -29,7 +29,7 @@ Use this data source to configure editable options for workspaces. - `legacy_variable_name` (String, Deprecated) Name of the legacy Terraform variable. Coder will use it to lookup the variable value. - `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution! - `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option)) -- `priority` (Number) The priority of a template parameter determines its position in the UI/CLI presentation. A higher priority parameter is positioned ahead of a lower priority one and parameters with the same priority are ordered by name in ascending order. +- `order` (Number) The order determines the position of a template parameter in the UI/CLI presentation. A parameter with lower order is positioned ahead of a high order one and parameters with the same order are sorted by name in ascending order. - `type` (String) The type of this parameter. Must be one of: "number", "string", "bool", or "list(string)". - `validation` (Block List, Max: 1) Validate the input of a parameter. (see [below for nested schema](#nestedblock--validation)) diff --git a/examples/resources/coder_parameter/resource.tf b/examples/resources/coder_parameter/resource.tf index d40ca2f2..15b747c4 100644 --- a/examples/resources/coder_parameter/resource.tf +++ b/examples/resources/coder_parameter/resource.tf @@ -41,18 +41,18 @@ data "coder_parameter" "is_public_instance" { } data "coder_parameter" "cores" { - name = "CPU Cores" - type = "number" - icon = "/icon/cpu.svg" - default = 3 - priority = 10 + name = "CPU Cores" + type = "number" + icon = "/icon/cpu.svg" + default = 3 + order = 10 } data "coder_parameter" "disk_size" { - name = "Disk Size" - type = "number" - default = "5" - priority = 8 + name = "Disk Size" + type = "number" + default = "5" + order = 8 validation { # This can apply to number. min = 0 diff --git a/provider/parameter.go b/provider/parameter.go index 5e2dbca0..920c2e2d 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -57,7 +57,7 @@ type Parameter struct { Validation []Validation Optional bool - Priority int + Order int LegacyVariableName string `mapstructure:"legacy_variable_name"` LegacyVariable string `mapstructure:"legacy_variable"` @@ -92,7 +92,7 @@ func parameterDataSource() *schema.Resource { Option interface{} Validation interface{} Optional interface{} - Priority interface{} + Order interface{} LegacyVariableName interface{} LegacyVariable interface{} @@ -125,7 +125,7 @@ func parameterDataSource() *schema.Resource { rd.Set("optional", val) return val }(), - Priority: rd.Get("priority"), + Order: rd.Get("order"), LegacyVariableName: rd.Get("legacy_variable_name"), LegacyVariable: rd.Get("legacy_variable"), }, ¶meter) @@ -335,10 +335,10 @@ func parameterDataSource() *schema.Resource { Computed: true, Description: "Whether this value is optional.", }, - "priority": { + "order": { Type: schema.TypeInt, Optional: true, - Description: "The priority of a template parameter determines its position in the UI/CLI presentation. A higher priority parameter is positioned ahead of a lower priority one and parameters with the same priority are ordered by name in ascending order.", + Description: "The order determines the position of a template parameter in the UI/CLI presentation. A parameter with lower order is positioned ahead of a high order one and parameters with the same order are sorted by name in ascending order.", }, "legacy_variable_name": { Type: schema.TypeString, diff --git a/provider/parameter_test.go b/provider/parameter_test.go index cff61c00..f591eeff 100644 --- a/provider/parameter_test.go +++ b/provider/parameter_test.go @@ -43,7 +43,7 @@ func TestParameter(t *testing.T) { icon = "/icon/east.svg" description = "Select for east!" } - priority = 5 + order = 5 } `, Check: func(state *terraform.ResourceState) { @@ -63,7 +63,7 @@ func TestParameter(t *testing.T) { "option.1.value": "us-east1-a", "option.1.icon": "/icon/east.svg", "option.1.description": "Select for east!", - "priority": "5", + "order": "5", } { require.Equal(t, value, attrs[key]) } From dbc0a67bd8262d38db98a47749bdbe4d5e60e9ab Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 28 Jun 2023 15:28:40 +0200 Subject: [PATCH 5/5] Fix --- docs/data-sources/parameter.md | 2 +- provider/parameter.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index 59723a6a..180a7d7b 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -29,7 +29,7 @@ Use this data source to configure editable options for workspaces. - `legacy_variable_name` (String, Deprecated) Name of the legacy Terraform variable. Coder will use it to lookup the variable value. - `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution! - `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option)) -- `order` (Number) The order determines the position of a template parameter in the UI/CLI presentation. A parameter with lower order is positioned ahead of a high order one and parameters with the same order are sorted by name in ascending order. +- `order` (Number) 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). - `type` (String) The type of this parameter. Must be one of: "number", "string", "bool", or "list(string)". - `validation` (Block List, Max: 1) Validate the input of a parameter. (see [below for nested schema](#nestedblock--validation)) diff --git a/provider/parameter.go b/provider/parameter.go index 920c2e2d..e8cfd4c6 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -338,7 +338,7 @@ func parameterDataSource() *schema.Resource { "order": { Type: schema.TypeInt, Optional: true, - Description: "The order determines the position of a template parameter in the UI/CLI presentation. A parameter with lower order is positioned ahead of a high order one and parameters with the same order are sorted by name in 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).", }, "legacy_variable_name": { Type: schema.TypeString,