Skip to content

feat: Prompt user for parameter values #137

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

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions docs/data-sources/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Use this data source to configure editable options for workspaces.
- `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).
- `prompt_user` (String) Prompt user for the parameter value. Coder will not persist it between workspace builds.
- `type` (String) The type of this parameter. Must be one of: "number", "string", "bool", or "list(string)".
- `validation` (Block List, Max: 1) Validate the input of a parameter. (see [below for nested schema](#nestedblock--validation))

Expand Down
5 changes: 3 additions & 2 deletions examples/resources/coder_parameter/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ data "coder_parameter" "cat_lives" {
}

data "coder_parameter" "fairy_tale" {
name = "Fairy Tale"
type = "string"
name = "Fairy Tale"
type = "string"
prompt_user = "always"
}

data "coder_parameter" "users" {
Expand Down
3 changes: 3 additions & 0 deletions provider/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestDecode(t *testing.T) {
const (
legacyVariable = "Legacy Variable"
legacyVariableName = "Legacy Variable Name"
promptUserAlways = "always"

displayName = "Display Name"
)
Expand All @@ -32,6 +33,7 @@ func TestDecode(t *testing.T) {
"max_disabled": true,
},
},
"prompt_user": promptUserAlways,
}

var param provider.Parameter
Expand All @@ -44,4 +46,5 @@ func TestDecode(t *testing.T) {
assert.True(t, param.Validation[0].MaxDisabled)
assert.Equal(t, 0, param.Validation[0].Min)
assert.False(t, param.Validation[0].MinDisabled)
assert.Equal(t, promptUserAlways, param.PromptUser)
}
12 changes: 10 additions & 2 deletions provider/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ type Parameter struct {
Option []Option
Validation []Validation
Optional bool

Order int
Order int
PromptUser string `mapstructure:"prompt_user"`

LegacyVariableName string `mapstructure:"legacy_variable_name"`
LegacyVariable string `mapstructure:"legacy_variable"`
Expand Down Expand Up @@ -93,6 +93,7 @@ func parameterDataSource() *schema.Resource {
Validation interface{}
Optional interface{}
Order interface{}
PromptUser interface{}

LegacyVariableName interface{}
LegacyVariable interface{}
Expand Down Expand Up @@ -126,6 +127,7 @@ func parameterDataSource() *schema.Resource {
return val
}(),
Order: rd.Get("order"),
PromptUser: rd.Get("prompt_user"),
LegacyVariableName: rd.Get("legacy_variable_name"),
LegacyVariable: rd.Get("legacy_variable"),
}, &parameter)
Expand Down Expand Up @@ -340,6 +342,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).",
},
"prompt_user": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"always"}, false),
Description: "Prompt user for the parameter value. Coder will not persist it between workspace builds.",
},
"legacy_variable_name": {
Type: schema.TypeString,
Optional: true,
Expand Down
2 changes: 2 additions & 0 deletions provider/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestParameter(t *testing.T) {
description = "Select for east!"
}
order = 5
prompt_user = "always"
}
`,
Check: func(state *terraform.ResourceState) {
Expand All @@ -64,6 +65,7 @@ func TestParameter(t *testing.T) {
"option.1.icon": "/icon/east.svg",
"option.1.description": "Select for east!",
"order": "5",
"prompt_user": "always",
} {
require.Equal(t, value, attrs[key])
}
Expand Down