From 3364654fb4c9f1005d67a4c88f36491b4a70f4f1 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Thu, 6 Jul 2023 10:54:42 +0200 Subject: [PATCH 1/2] feat: drop support for legacy variables --- docs/data-sources/parameter.md | 2 - docs/index.md | 2 +- .../resources/coder_parameter/resource.tf | 4 +- .../coder_parameter_migration/resource.tf | 14 ----- provider/decode_test.go | 17 ++---- provider/examples_test.go | 14 ----- provider/parameter.go | 44 +++------------- provider/parameter_test.go | 52 ------------------- provider/provider.go | 2 + 9 files changed, 14 insertions(+), 137 deletions(-) delete mode 100644 examples/resources/coder_parameter_migration/resource.tf diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index 100c4f91..fc8100e7 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -26,8 +26,6 @@ Use this data source to configure editable options for workspaces. - `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. - `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. The lowest order is shown first and parameters with equal order are sorted by name (ascending order). diff --git a/docs/index.md b/docs/index.md index 154423c1..25e15460 100644 --- a/docs/index.md +++ b/docs/index.md @@ -62,5 +62,5 @@ resource "google_compute_instance" "dev" { ### Optional -- `feature_use_managed_variables` (Boolean) Feature: use managed Terraform variables. If disabled, Terraform variables will be included in legacy Parameter Schema. +- `feature_use_managed_variables` (Boolean, Deprecated) Feature: use managed Terraform variables. If disabled, Terraform variables will be included in legacy Parameter Schema. - `url` (String) The URL to access Coder. \ No newline at end of file diff --git a/examples/resources/coder_parameter/resource.tf b/examples/resources/coder_parameter/resource.tf index ca2f9ec4..bb986183 100644 --- a/examples/resources/coder_parameter/resource.tf +++ b/examples/resources/coder_parameter/resource.tf @@ -1,6 +1,4 @@ -provider "coder" { - feature_use_managed_variables = true -} +provider "coder" {} data "coder_parameter" "example" { name = "Region" diff --git a/examples/resources/coder_parameter_migration/resource.tf b/examples/resources/coder_parameter_migration/resource.tf deleted file mode 100644 index 1317dce1..00000000 --- a/examples/resources/coder_parameter_migration/resource.tf +++ /dev/null @@ -1,14 +0,0 @@ -provider "coder" {} - -variable "old_account_name" { - type = string - default = "fake-user" # for testing purposes, no need to set via env TF_... -} - -data "coder_parameter" "account_name" { - name = "Account Name" - type = "string" - - legacy_variable_name = "old_account_name" - legacy_variable = var.old_account_name -} \ No newline at end of file diff --git a/provider/decode_test.go b/provider/decode_test.go index de56922c..a5e20b14 100644 --- a/provider/decode_test.go +++ b/provider/decode_test.go @@ -11,19 +11,12 @@ import ( ) func TestDecode(t *testing.T) { - const ( - legacyVariable = "Legacy Variable" - legacyVariableName = "Legacy Variable Name" - - displayName = "Display Name" - ) + const displayName = "Display Name" aMap := map[string]interface{}{ - "name": "Parameter Name", - "type": "number", - "display_name": displayName, - "legacy_variable": legacyVariable, - "legacy_variable_name": legacyVariableName, + "name": "Parameter Name", + "type": "number", + "display_name": displayName, "validation": []map[string]interface{}{ { "min": nil, @@ -38,8 +31,6 @@ func TestDecode(t *testing.T) { err := mapstructure.Decode(aMap, ¶m) require.NoError(t, err) assert.Equal(t, displayName, param.DisplayName) - assert.Equal(t, legacyVariable, param.LegacyVariable) - assert.Equal(t, legacyVariableName, param.LegacyVariableName) assert.Equal(t, 5, param.Validation[0].Max) assert.True(t, param.Validation[0].MaxDisabled) assert.Equal(t, 0, param.Validation[0].Min) diff --git a/provider/examples_test.go b/provider/examples_test.go index 12f32800..263e65ce 100644 --- a/provider/examples_test.go +++ b/provider/examples_test.go @@ -26,20 +26,6 @@ func TestExamples(t *testing.T) { }}, }) }) - - t.Run("coder_parameter_migration", func(t *testing.T) { - t.Parallel() - - resource.Test(t, resource.TestCase{ - Providers: map[string]*schema.Provider{ - "coder": provider.New(), - }, - IsUnitTest: true, - Steps: []resource.TestStep{{ - Config: mustReadFile(t, "../examples/resources/coder_parameter_migration/resource.tf"), - }}, - }) - }) } func mustReadFile(t *testing.T, path string) string { diff --git a/provider/parameter.go b/provider/parameter.go index da09720a..5791a323 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -58,9 +58,6 @@ type Parameter struct { Optional bool Order int Ephemeral bool - - LegacyVariableName string `mapstructure:"legacy_variable_name"` - LegacyVariable string `mapstructure:"legacy_variable"` } func parameterDataSource() *schema.Resource { @@ -94,9 +91,6 @@ func parameterDataSource() *schema.Resource { Optional interface{} Order interface{} Ephemeral interface{} - - LegacyVariableName interface{} - LegacyVariable interface{} }{ Value: rd.Get("value"), Name: rd.Get("name"), @@ -104,20 +98,10 @@ func parameterDataSource() *schema.Resource { Description: rd.Get("description"), Type: rd.Get("type"), Mutable: rd.Get("mutable"), - Default: func() interface{} { - standardMode := rd.GetRawConfig().AsValueMap()["legacy_variable"].IsNull() - if standardMode { - return rd.Get("default") - } - - // legacy variable is linked - legacyVariable := rd.GetRawConfig().AsValueMap()["legacy_variable"].AsString() - rd.Set("default", legacyVariable) - return legacyVariable - }(), - Icon: rd.Get("icon"), - Option: rd.Get("option"), - Validation: fixedValidation, + Default: rd.Get("default"), + Icon: rd.Get("icon"), + Option: rd.Get("option"), + Validation: fixedValidation, Optional: func() bool { // This hack allows for checking if the "default" field is present in the .tf file. // If "default" is missing or is "null", then it means that this field is required, @@ -126,10 +110,8 @@ func parameterDataSource() *schema.Resource { rd.Set("optional", val) return val }(), - Order: rd.Get("order"), - Ephemeral: rd.Get("ephemeral"), - LegacyVariableName: rd.Get("legacy_variable_name"), - LegacyVariable: rd.Get("legacy_variable"), + Order: rd.Get("order"), + Ephemeral: rd.Get("ephemeral"), }, ¶meter) if err != nil { return diag.Errorf("decode parameter: %s", err) @@ -352,20 +334,6 @@ func parameterDataSource() *schema.Resource { 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, - RequiredWith: []string{"legacy_variable"}, - Description: "Name of the legacy Terraform variable. Coder will use it to lookup the variable value.", - Deprecated: "Effective from Coder v0.24.0, the parameter migration feature is no longer available. This attribute will be removed in the nearest future.", - }, - "legacy_variable": { - Type: schema.TypeString, - Optional: true, - RequiredWith: []string{"legacy_variable_name"}, - Description: "Reference to the Terraform variable. Coder will use it to lookup the default value.", - Deprecated: "Effective from Coder v0.24.0, the parameter migration feature is no longer available. This attribute will be removed in the nearest future.", - }, }, } } diff --git a/provider/parameter_test.go b/provider/parameter_test.go index 78075c18..4e21cea8 100644 --- a/provider/parameter_test.go +++ b/provider/parameter_test.go @@ -353,32 +353,6 @@ func TestParameter(t *testing.T) { require.Equal(t, expected, state.Primary.Attributes[key]) } }, - }, { - Name: "LegacyVariable", - Config: ` -variable "old_region" { - type = string - default = "fake-region" # for testing purposes, no need to set via env TF_... -} - -data "coder_parameter" "region" { - name = "Region" - type = "string" - default = "will-be-ignored" - legacy_variable_name = "old_region" - legacy_variable = var.old_region -}`, - Check: func(state *terraform.ResourceState) { - for key, expected := range map[string]string{ - "name": "Region", - "type": "string", - "default": "fake-region", - "legacy_variable_name": "old_region", - "legacy_variable": "fake-region", - } { - require.Equal(t, expected, state.Primary.Attributes[key]) - } - }, }, { Name: "ListOfStrings", Config: ` @@ -398,32 +372,6 @@ data "coder_parameter" "region" { require.Equal(t, expected, attributeValue) } }, - }, { - Name: "ListOfStringsButMigrated", - Config: ` -variable "old_region" { - type = list(string) - default = ["us-west-1a"] # for testing purposes, no need to set via env TF_... -} - -data "coder_parameter" "region" { - name = "Region" - type = "list(string)" - default = "[\"us-east-1\", \"eu-west-1\", \"ap-northeast-1\"]" - legacy_variable_name = "old_region" - legacy_variable = jsonencode(var.old_region) -}`, - Check: func(state *terraform.ResourceState) { - for key, expected := range map[string]string{ - "name": "Region", - "type": "list(string)", - "default": `["us-west-1a"]`, - } { - attributeValue, ok := state.Primary.Attributes[key] - require.True(t, ok, "attribute %q is expected", key) - require.Equal(t, expected, attributeValue) - } - }, }, { Name: "NumberValidation_Max", Config: ` diff --git a/provider/provider.go b/provider/provider.go index a77774cd..ae77f668 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -38,7 +38,9 @@ func New() *schema.Provider { "feature_use_managed_variables": { Type: schema.TypeBool, Description: "Feature: use managed Terraform variables. If disabled, Terraform variables will be included in legacy Parameter Schema.", + Default: true, Optional: true, + Deprecated: "Terraform variables are now exclusively utilized for template-wide variables after the removal of support for legacy parameters.", }, }, ConfigureContextFunc: func(c context.Context, resourceData *schema.ResourceData) (interface{}, diag.Diagnostics) { From 7eea671e97ecf0c234d924d9e76ffb60afcfc9a2 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Thu, 6 Jul 2023 11:56:56 +0200 Subject: [PATCH 2/2] Deprecated --- docs/index.md | 2 +- provider/provider.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 25e15460..13bf6b44 100644 --- a/docs/index.md +++ b/docs/index.md @@ -62,5 +62,5 @@ resource "google_compute_instance" "dev" { ### Optional -- `feature_use_managed_variables` (Boolean, Deprecated) Feature: use managed Terraform variables. If disabled, Terraform variables will be included in legacy Parameter Schema. +- `feature_use_managed_variables` (Boolean, Deprecated) Feature: use managed Terraform variables. The feature flag is not used anymore as Terraform variables are now exclusively utilized for template-wide variables. - `url` (String) The URL to access Coder. \ No newline at end of file diff --git a/provider/provider.go b/provider/provider.go index ae77f668..32058b5b 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -37,7 +37,7 @@ func New() *schema.Provider { }, "feature_use_managed_variables": { Type: schema.TypeBool, - Description: "Feature: use managed Terraform variables. If disabled, Terraform variables will be included in legacy Parameter Schema.", + Description: "Feature: use managed Terraform variables. The feature flag is not used anymore as Terraform variables are now exclusively utilized for template-wide variables.", Default: true, Optional: true, Deprecated: "Terraform variables are now exclusively utilized for template-wide variables after the removal of support for legacy parameters.",