diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index 180a7d7b..100c4f91 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -24,6 +24,7 @@ Use this data source to configure editable options for workspaces. - `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. +- `ephemeral` (Boolean) The value of an ephemeral parameter will not be preserved between consecutive workspace builds. - `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, Deprecated) Reference to the Terraform variable. Coder will use it to lookup the default value. - `legacy_variable_name` (String, Deprecated) 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 15b747c4..ca2f9ec4 100644 --- a/examples/resources/coder_parameter/resource.tf +++ b/examples/resources/coder_parameter/resource.tf @@ -74,8 +74,10 @@ data "coder_parameter" "cat_lives" { } data "coder_parameter" "fairy_tale" { - name = "Fairy Tale" - type = "string" + name = "Fairy Tale" + type = "string" + mutable = true + ephemeral = true } data "coder_parameter" "users" { diff --git a/provider/parameter.go b/provider/parameter.go index e8cfd4c6..da09720a 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -56,8 +56,8 @@ type Parameter struct { Option []Option Validation []Validation Optional bool - - Order int + Order int + Ephemeral bool LegacyVariableName string `mapstructure:"legacy_variable_name"` LegacyVariable string `mapstructure:"legacy_variable"` @@ -93,6 +93,7 @@ func parameterDataSource() *schema.Resource { Validation interface{} Optional interface{} Order interface{} + Ephemeral interface{} LegacyVariableName interface{} LegacyVariable interface{} @@ -126,6 +127,7 @@ func parameterDataSource() *schema.Resource { return val }(), Order: rd.Get("order"), + Ephemeral: rd.Get("ephemeral"), LegacyVariableName: rd.Get("legacy_variable_name"), LegacyVariable: rd.Get("legacy_variable"), }, ¶meter) @@ -146,6 +148,10 @@ func parameterDataSource() *schema.Resource { } rd.Set("value", value) + if !parameter.Mutable && parameter.Ephemeral { + return diag.Errorf("parameter can't be immutable and ephemeral") + } + if len(parameter.Validation) == 1 { validation := ¶meter.Validation[0] err = validation.Valid(parameter.Type, value) @@ -340,6 +346,12 @@ func parameterDataSource() *schema.Resource { Optional: true, 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).", }, + "ephemeral": { + Type: schema.TypeBool, + Default: false, + Optional: true, + Description: "The value of an ephemeral parameter will not be preserved between consecutive workspace builds.", + }, "legacy_variable_name": { Type: schema.TypeString, Optional: true, diff --git a/provider/parameter_test.go b/provider/parameter_test.go index f591eeff..78075c18 100644 --- a/provider/parameter_test.go +++ b/provider/parameter_test.go @@ -44,6 +44,7 @@ func TestParameter(t *testing.T) { description = "Select for east!" } order = 5 + ephemeral = true } `, Check: func(state *terraform.ResourceState) { @@ -64,6 +65,7 @@ func TestParameter(t *testing.T) { "option.1.icon": "/icon/east.svg", "option.1.description": "Select for east!", "order": "5", + "ephemeral": "true", } { require.Equal(t, value, attrs[key]) } @@ -602,6 +604,17 @@ data "coder_parameter" "region" { } `, ExpectError: regexp.MustCompile("a min cannot be specified for a bool type"), + }, { + Name: "ImmutableEphemeralError", + Config: ` + data "coder_parameter" "region" { + name = "Region" + type = "string" + mutable = false + ephemeral = true + } + `, + ExpectError: regexp.MustCompile("parameter can't be immutable and ephemeral"), }} { tc := tc t.Run(tc.Name, func(t *testing.T) {