From 8a2373823d845fb64d19743543b79170d2e8ba48 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Fri, 31 Mar 2023 10:52:15 +0200 Subject: [PATCH] feat: Add display_name to coder_parameter --- docs/data-sources/parameter.md | 3 ++- examples/resources/coder_parameter/resource.tf | 7 ++++--- provider/parameter.go | 10 +++++++++- provider/parameter_test.go | 6 ++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index 7483c9d0..6b4b7c09 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -17,12 +17,13 @@ Use this data source to configure editable options for workspaces. ### Required -- `name` (String) The name of the parameter as it will appear in the interface. If this is changed, developers will be re-prompted for a new value. +- `name` (String) The name of the parameter. If this is changed, developers will be re-prompted for a new value. ### Optional - `default` (String) A default value for the parameter. - `description` (String) Describe what this parameter does. +- `display_name` (String) The displayed name of the parameter as it will appear in the interface. - `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `data.coder_workspace.me.access_url + "/icon/"`. - `legacy_variable` (String) Reference to the Terraform variable. Coder will use it to lookup the default value. - `legacy_variable_name` (String) Name of the legacy Terraform variable. Coder will use it to lookup the variable value. diff --git a/examples/resources/coder_parameter/resource.tf b/examples/resources/coder_parameter/resource.tf index cbbc3ec7..a89ce1b8 100644 --- a/examples/resources/coder_parameter/resource.tf +++ b/examples/resources/coder_parameter/resource.tf @@ -77,7 +77,8 @@ data "coder_parameter" "fairy_tale" { } data "coder_parameter" "users" { - name = "System users" - type = "list(string)" - default = jsonencode(["root", "user1", "user2"]) + name = "system_users" + display_name = "System users" + type = "list(string)" + default = jsonencode(["root", "user1", "user2"]) } \ No newline at end of file diff --git a/provider/parameter.go b/provider/parameter.go index d908f2ce..1260e1ef 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -42,6 +42,7 @@ const ( type Parameter struct { Value string Name string + DisplayName string Description string Type string Mutable bool @@ -65,6 +66,7 @@ func parameterDataSource() *schema.Resource { err := mapstructure.Decode(struct { Value interface{} Name interface{} + DisplayName interface{} Description interface{} Type interface{} Mutable interface{} @@ -79,6 +81,7 @@ func parameterDataSource() *schema.Resource { }{ Value: rd.Get("value"), Name: rd.Get("name"), + DisplayName: rd.Get("display_name"), Description: rd.Get("description"), Type: rd.Get("type"), Mutable: rd.Get("mutable"), @@ -170,7 +173,12 @@ func parameterDataSource() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - Description: "The name of the parameter as it will appear in the interface. If this is changed, developers will be re-prompted for a new value.", + Description: "The name of the parameter. If this is changed, developers will be re-prompted for a new value.", + }, + "display_name": { + Type: schema.TypeString, + Optional: true, + Description: "The displayed name of the parameter as it will appear in the interface.", }, "description": { Type: schema.TypeString, diff --git a/provider/parameter_test.go b/provider/parameter_test.go index df1847e3..c349190b 100644 --- a/provider/parameter_test.go +++ b/provider/parameter_test.go @@ -22,7 +22,8 @@ func TestParameter(t *testing.T) { Name: "FieldsExist", Config: ` data "coder_parameter" "region" { - name = "Region" + name = "region" + display_name = "Region" type = "string" description = <<-EOT # Select the machine image @@ -47,7 +48,8 @@ func TestParameter(t *testing.T) { Check: func(state *terraform.ResourceState) { attrs := state.Primary.Attributes for key, value := range map[string]interface{}{ - "name": "Region", + "name": "region", + "display_name": "Region", "type": "string", "description": "# Select the machine image\nSee the [registry](https://container.registry.blah/namespace) for options.\n", "mutable": "true",