Skip to content

Commit

Permalink
feat: Add legacy_variable_name to parameter (#110)
Browse files Browse the repository at this point in the history
* feat: Add legacy_variable_name to parameter

* fix

* fix

* Fix
  • Loading branch information
mtojek committed Mar 10, 2023
1 parent 7c0f341 commit 9bcdcd6
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 180 deletions.
3 changes: 2 additions & 1 deletion docs/data-sources/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ 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.
- `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) The name of the Terraform variable used by legacy parameters. Coder will use it to lookup the parameter value.
- `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.
- `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))
- `type` (String) The type of this parameter. Must be one of: "number", "string", or "bool".
Expand Down
8 changes: 5 additions & 3 deletions examples/resources/coder_parameter_migration/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ variable "old_account_name" {
}

data "coder_parameter" "account_name" {
name = "Account Name"
type = "string"
legacy_variable = var.old_account_name
name = "Account Name"
type = "string"

legacy_variable_name = "old_account_name"
legacy_variable = var.old_account_name
}
22 changes: 16 additions & 6 deletions provider/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type Parameter struct {
Validation []Validation
Optional bool

LegacyVariable string
LegacyVariableName string
LegacyVariable string
}

func parameterDataSource() *schema.Resource {
Expand All @@ -72,7 +73,8 @@ func parameterDataSource() *schema.Resource {
Validation interface{}
Optional interface{}

LegacyVariable interface{}
LegacyVariableName interface{}
LegacyVariable interface{}
}{
Value: rd.Get("value"),
Name: rd.Get("name"),
Expand Down Expand Up @@ -101,7 +103,8 @@ func parameterDataSource() *schema.Resource {
rd.Set("optional", val)
return val
}(),
LegacyVariable: rd.Get("legacy_variable"),
LegacyVariableName: rd.Get("legacy_variable_name"),
LegacyVariable: rd.Get("legacy_variable"),
}, &parameter)
if err != nil {
return diag.Errorf("decode parameter: %s", err)
Expand Down Expand Up @@ -297,10 +300,17 @@ func parameterDataSource() *schema.Resource {
Computed: true,
Description: "Whether this value is optional.",
},
"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.",
},
"legacy_variable": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the Terraform variable used by legacy parameters. Coder will use it to lookup the parameter value.",
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.",
},
},
}
Expand Down

0 comments on commit 9bcdcd6

Please sign in to comment.