Skip to content

Commit

Permalink
feat: ephemeral parameters must be optional (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek committed Jul 18, 2023
1 parent 5d01ad6 commit 1882c77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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")
}

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

0 comments on commit 1882c77

Please sign in to comment.