diff --git a/examples/resources/coder_parameter/resource.tf b/examples/resources/coder_parameter/resource.tf index 9057b3a1..9e6ef8a0 100644 --- a/examples/resources/coder_parameter/resource.tf +++ b/examples/resources/coder_parameter/resource.tf @@ -1,43 +1,43 @@ data "coder_parameter" "example" { - display_name = "Region" - description = "Specify a region to place your workspace." - immutable = true - type = "string" + name = "Region" + description = "Specify a region to place your workspace." + mutable = false + type = "string" option { value = "us-central1-a" - label = "US Central" + name = "US Central" icon = "/icon/usa.svg" } option { value = "asia-central1-a" - label = "Asia" + name = "Asia" icon = "/icon/asia.svg" } } data "coder_parameter" "ami" { - display_name = "Machine Image" + name = "Machine Image" option { value = "ami-xxxxxxxx" - label = "Ubuntu" + name = "Ubuntu" icon = "/icon/ubuntu.svg" } } -data "coder_parameter" "image" { - display_name = "Docker Image" - icon = "/icon/docker.svg" - type = "bool" +data "coder_parameter" "is_public_instance" { + name = "Is public instance?" + icon = "/icon/docker.svg" + type = "bool" } data "coder_parameter" "cores" { - display_name = "CPU Cores" - icon = "/icon/" + name = "CPU Cores" + icon = "/icon/" } data "coder_parameter" "disk_size" { - display_name = "Disk Size" - type = "number" + name = "Disk Size" + type = "number" validation { # This can apply to number and string types. min = 0 diff --git a/provider/parameter.go b/provider/parameter.go index 0a67b0c2..4c6331b7 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -288,6 +288,9 @@ func (v *Validation) Valid(typ, value string) error { } switch typ { case "bool": + if value != "true" && value != "false" { + return fmt.Errorf(`boolean value can be either "true" or "false"`) + } return nil case "string": if v.Regex == "" { @@ -307,13 +310,13 @@ func (v *Validation) Valid(typ, value string) error { case "number": num, err := strconv.Atoi(value) if err != nil { - return fmt.Errorf("parse value %s as int: %s", value, err) + return fmt.Errorf("value %q is not a number", value) } if num < v.Min { - return fmt.Errorf("provided value %d is less than the minimum %d", num, v.Min) + return fmt.Errorf("value %d is less than the minimum %d", num, v.Min) } if num > v.Max { - return fmt.Errorf("provided value %d is more than the maximum %d", num, v.Max) + return fmt.Errorf("value %d is more than the maximum %d", num, v.Max) } } return nil diff --git a/provider/parameter_test.go b/provider/parameter_test.go index b4de3f19..88ddcf4b 100644 --- a/provider/parameter_test.go +++ b/provider/parameter_test.go @@ -294,7 +294,7 @@ func TestValueValidatesType(t *testing.T) { Name: "InvalidNumber", Type: "number", Value: "hi", - Error: regexp.MustCompile("parse value hi as int"), + Error: regexp.MustCompile("is not a number"), }, { Name: "NumberBelowMin", Type: "number", @@ -307,6 +307,11 @@ func TestValueValidatesType(t *testing.T) { Value: "1", Max: 0, Error: regexp.MustCompile("is more than the maximum"), + }, { + Name: "InvalidBool", + Type: "bool", + Value: "cat", + Error: regexp.MustCompile("boolean value can be either"), }} { tc := tc t.Run(tc.Name, func(t *testing.T) { @@ -318,7 +323,7 @@ func TestValueValidatesType(t *testing.T) { } err := v.Valid(tc.Type, tc.Value) if tc.Error != nil { - require.True(t, tc.Error.MatchString(err.Error())) + require.True(t, tc.Error.MatchString(err.Error()), "got: %s", err.Error()) } }) }