Skip to content

feat: drop support for legacy variables #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/data-sources/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<path>"`.
- `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).
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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.
4 changes: 1 addition & 3 deletions examples/resources/coder_parameter/resource.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
provider "coder" {
feature_use_managed_variables = true
}
provider "coder" {}

data "coder_parameter" "example" {
name = "Region"
Expand Down
14 changes: 0 additions & 14 deletions examples/resources/coder_parameter_migration/resource.tf

This file was deleted.

17 changes: 4 additions & 13 deletions provider/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,8 +31,6 @@ func TestDecode(t *testing.T) {
err := mapstructure.Decode(aMap, &param)
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)
Expand Down
14 changes: 0 additions & 14 deletions provider/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 6 additions & 38 deletions provider/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -94,30 +91,17 @@ func parameterDataSource() *schema.Resource {
Optional interface{}
Order interface{}
Ephemeral interface{}

LegacyVariableName interface{}
LegacyVariable interface{}
}{
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"),
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,
Expand All @@ -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"),
}, &parameter)
if err != nil {
return diag.Errorf("decode parameter: %s", err)
Expand Down Expand Up @@ -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.",
},
},
}
}
Expand Down
52 changes: 0 additions & 52 deletions provider/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand All @@ -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: `
Expand Down
4 changes: 3 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ 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.",
},
},
ConfigureContextFunc: func(c context.Context, resourceData *schema.ResourceData) (interface{}, diag.Diagnostics) {
Expand Down