Skip to content

feat: ephemeral parameters must be optional #141

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 1 commit into from
Jul 18, 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
1 change: 1 addition & 0 deletions examples/resources/coder_parameter/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ data "coder_parameter" "fairy_tale" {
name = "Fairy Tale"
type = "string"
mutable = true
default = "Hansel and Gretel"
ephemeral = true
}

Expand Down
4 changes: 4 additions & 0 deletions provider/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func parameterDataSource() *schema.Resource {
return diag.Errorf("parameter can't be immutable and ephemeral")
}

if !parameter.Optional && parameter.Ephemeral {
return diag.Errorf("ephemeral parameter requires the default property")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check: do parameters have an optional field or is it inferred by setting default, and is that the only way to do it? (I always stop to ask when I see the check and message say something different.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do parameters have an optional field

No.

is it inferred by setting default

Yes 👍

is that the only way to do it

Yes 👍

}

if len(parameter.Validation) == 1 {
validation := &parameter.Validation[0]
err = validation.Valid(parameter.Type, value)
Expand Down
14 changes: 14 additions & 0 deletions provider/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestParameter(t *testing.T) {
EOT
mutable = true
icon = "/icon/region.svg"
default = "us-east1-a"
option {
name = "US Central"
value = "us-central1-a"
Expand Down Expand Up @@ -65,6 +66,7 @@ func TestParameter(t *testing.T) {
"option.1.icon": "/icon/east.svg",
"option.1.description": "Select for east!",
"order": "5",
"default": "us-east1-a",
"ephemeral": "true",
} {
require.Equal(t, value, attrs[key])
Expand Down Expand Up @@ -558,11 +560,23 @@ data "coder_parameter" "region" {
data "coder_parameter" "region" {
name = "Region"
type = "string"
default = "abc"
mutable = false
ephemeral = true
}
`,
ExpectError: regexp.MustCompile("parameter can't be immutable and ephemeral"),
}, {
Name: "RequiredEphemeralError",
Config: `
data "coder_parameter" "region" {
name = "Region"
type = "string"
mutable = true
ephemeral = true
}
`,
ExpectError: regexp.MustCompile("ephemeral parameter requires the default property"),
}} {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
Expand Down