Skip to content

Commit 9bcdcd6

Browse files
authored
feat: Add legacy_variable_name to parameter (#110)
* feat: Add legacy_variable_name to parameter * fix * fix * Fix
1 parent 7c0f341 commit 9bcdcd6

File tree

4 files changed

+195
-180
lines changed

4 files changed

+195
-180
lines changed

docs/data-sources/parameter.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Use this data source to configure editable options for workspaces.
2424
- `default` (String) A default value for the parameter.
2525
- `description` (String) Describe what this parameter does.
2626
- `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>"`.
27-
- `legacy_variable` (String) The name of the Terraform variable used by legacy parameters. Coder will use it to lookup the parameter value.
27+
- `legacy_variable` (String) Reference to the Terraform variable. Coder will use it to lookup the default value.
28+
- `legacy_variable_name` (String) Name of the legacy Terraform variable. Coder will use it to lookup the variable value.
2829
- `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution!
2930
- `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option))
3031
- `type` (String) The type of this parameter. Must be one of: "number", "string", or "bool".

examples/resources/coder_parameter_migration/resource.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ variable "old_account_name" {
66
}
77

88
data "coder_parameter" "account_name" {
9-
name = "Account Name"
10-
type = "string"
11-
legacy_variable = var.old_account_name
9+
name = "Account Name"
10+
type = "string"
11+
12+
legacy_variable_name = "old_account_name"
13+
legacy_variable = var.old_account_name
1214
}

provider/parameter.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ type Parameter struct {
5050
Validation []Validation
5151
Optional bool
5252

53-
LegacyVariable string
53+
LegacyVariableName string
54+
LegacyVariable string
5455
}
5556

5657
func parameterDataSource() *schema.Resource {
@@ -72,7 +73,8 @@ func parameterDataSource() *schema.Resource {
7273
Validation interface{}
7374
Optional interface{}
7475

75-
LegacyVariable interface{}
76+
LegacyVariableName interface{}
77+
LegacyVariable interface{}
7678
}{
7779
Value: rd.Get("value"),
7880
Name: rd.Get("name"),
@@ -101,7 +103,8 @@ func parameterDataSource() *schema.Resource {
101103
rd.Set("optional", val)
102104
return val
103105
}(),
104-
LegacyVariable: rd.Get("legacy_variable"),
106+
LegacyVariableName: rd.Get("legacy_variable_name"),
107+
LegacyVariable: rd.Get("legacy_variable"),
105108
}, &parameter)
106109
if err != nil {
107110
return diag.Errorf("decode parameter: %s", err)
@@ -297,10 +300,17 @@ func parameterDataSource() *schema.Resource {
297300
Computed: true,
298301
Description: "Whether this value is optional.",
299302
},
303+
"legacy_variable_name": {
304+
Type: schema.TypeString,
305+
Optional: true,
306+
RequiredWith: []string{"legacy_variable"},
307+
Description: "Name of the legacy Terraform variable. Coder will use it to lookup the variable value.",
308+
},
300309
"legacy_variable": {
301-
Type: schema.TypeString,
302-
Optional: true,
303-
Description: "The name of the Terraform variable used by legacy parameters. Coder will use it to lookup the parameter value.",
310+
Type: schema.TypeString,
311+
Optional: true,
312+
RequiredWith: []string{"legacy_variable_name"},
313+
Description: "Reference to the Terraform variable. Coder will use it to lookup the default value.",
304314
},
305315
},
306316
}

0 commit comments

Comments
 (0)