File tree Expand file tree Collapse file tree 3 files changed +29
-21
lines changed
examples/resources/coder_parameter Expand file tree Collapse file tree 3 files changed +29
-21
lines changed Original file line number Diff line number Diff line change 11data "coder_parameter" "example" {
2- display_name = " Region"
3- description = " Specify a region to place your workspace."
4- immutable = true
5- type = " string"
2+ name = " Region"
3+ description = " Specify a region to place your workspace."
4+ mutable = false
5+ type = " string"
66 option {
77 value = " us-central1-a"
8- label = " US Central"
8+ name = " US Central"
99 icon = " /icon/usa.svg"
1010 }
1111 option {
1212 value = " asia-central1-a"
13- label = " Asia"
13+ name = " Asia"
1414 icon = " /icon/asia.svg"
1515 }
1616}
1717
1818data "coder_parameter" "ami" {
19- display_name = " Machine Image"
19+ name = " Machine Image"
2020 option {
2121 value = " ami-xxxxxxxx"
22- label = " Ubuntu"
22+ name = " Ubuntu"
2323 icon = " /icon/ubuntu.svg"
2424 }
2525}
2626
27- data "coder_parameter" "image " {
28- display_name = " Docker Image "
29- icon = " /icon/docker.svg"
30- type = " bool"
27+ data "coder_parameter" "is_public_instance " {
28+ name = " Is public instance? "
29+ icon = " /icon/docker.svg"
30+ type = " bool"
3131}
3232
3333data "coder_parameter" "cores" {
34- display_name = " CPU Cores"
35- icon = " /icon/"
34+ name = " CPU Cores"
35+ icon = " /icon/"
3636}
3737
3838data "coder_parameter" "disk_size" {
39- display_name = " Disk Size"
40- type = " number"
39+ name = " Disk Size"
40+ type = " number"
4141 validation {
4242 # This can apply to number and string types.
4343 min = 0
Original file line number Diff line number Diff line change @@ -288,6 +288,9 @@ func (v *Validation) Valid(typ, value string) error {
288288 }
289289 switch typ {
290290 case "bool" :
291+ if value != "true" && value != "false" {
292+ return fmt .Errorf (`boolean value can be either "true" or "false"` )
293+ }
291294 return nil
292295 case "string" :
293296 if v .Regex == "" {
@@ -307,13 +310,13 @@ func (v *Validation) Valid(typ, value string) error {
307310 case "number" :
308311 num , err := strconv .Atoi (value )
309312 if err != nil {
310- return fmt .Errorf ("parse value %s as int: %s " , value , err )
313+ return fmt .Errorf ("value %q is not a number " , value )
311314 }
312315 if num < v .Min {
313- return fmt .Errorf ("provided value %d is less than the minimum %d" , num , v .Min )
316+ return fmt .Errorf ("value %d is less than the minimum %d" , num , v .Min )
314317 }
315318 if num > v .Max {
316- return fmt .Errorf ("provided value %d is more than the maximum %d" , num , v .Max )
319+ return fmt .Errorf ("value %d is more than the maximum %d" , num , v .Max )
317320 }
318321 }
319322 return nil
Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ func TestValueValidatesType(t *testing.T) {
294294 Name : "InvalidNumber" ,
295295 Type : "number" ,
296296 Value : "hi" ,
297- Error : regexp .MustCompile ("parse value hi as int " ),
297+ Error : regexp .MustCompile ("is not a number " ),
298298 }, {
299299 Name : "NumberBelowMin" ,
300300 Type : "number" ,
@@ -307,6 +307,11 @@ func TestValueValidatesType(t *testing.T) {
307307 Value : "1" ,
308308 Max : 0 ,
309309 Error : regexp .MustCompile ("is more than the maximum" ),
310+ }, {
311+ Name : "InvalidBool" ,
312+ Type : "bool" ,
313+ Value : "cat" ,
314+ Error : regexp .MustCompile ("boolean value can be either" ),
310315 }} {
311316 tc := tc
312317 t .Run (tc .Name , func (t * testing.T ) {
@@ -318,7 +323,7 @@ func TestValueValidatesType(t *testing.T) {
318323 }
319324 err := v .Valid (tc .Type , tc .Value )
320325 if tc .Error != nil {
321- require .True (t , tc .Error .MatchString (err .Error ()))
326+ require .True (t , tc .Error .MatchString (err .Error ()), "got: %s" , err . Error () )
322327 }
323328 })
324329 }
You can’t perform that action at this time.
0 commit comments