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 1
1
data "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"
6
6
option {
7
7
value = " us-central1-a"
8
- label = " US Central"
8
+ name = " US Central"
9
9
icon = " /icon/usa.svg"
10
10
}
11
11
option {
12
12
value = " asia-central1-a"
13
- label = " Asia"
13
+ name = " Asia"
14
14
icon = " /icon/asia.svg"
15
15
}
16
16
}
17
17
18
18
data "coder_parameter" "ami" {
19
- display_name = " Machine Image"
19
+ name = " Machine Image"
20
20
option {
21
21
value = " ami-xxxxxxxx"
22
- label = " Ubuntu"
22
+ name = " Ubuntu"
23
23
icon = " /icon/ubuntu.svg"
24
24
}
25
25
}
26
26
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"
31
31
}
32
32
33
33
data "coder_parameter" "cores" {
34
- display_name = " CPU Cores"
35
- icon = " /icon/"
34
+ name = " CPU Cores"
35
+ icon = " /icon/"
36
36
}
37
37
38
38
data "coder_parameter" "disk_size" {
39
- display_name = " Disk Size"
40
- type = " number"
39
+ name = " Disk Size"
40
+ type = " number"
41
41
validation {
42
42
# This can apply to number and string types.
43
43
min = 0
Original file line number Diff line number Diff line change @@ -288,6 +288,9 @@ func (v *Validation) Valid(typ, value string) error {
288
288
}
289
289
switch typ {
290
290
case "bool" :
291
+ if value != "true" && value != "false" {
292
+ return fmt .Errorf (`boolean value can be either "true" or "false"` )
293
+ }
291
294
return nil
292
295
case "string" :
293
296
if v .Regex == "" {
@@ -307,13 +310,13 @@ func (v *Validation) Valid(typ, value string) error {
307
310
case "number" :
308
311
num , err := strconv .Atoi (value )
309
312
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 )
311
314
}
312
315
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 )
314
317
}
315
318
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 )
317
320
}
318
321
}
319
322
return nil
Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ func TestValueValidatesType(t *testing.T) {
294
294
Name : "InvalidNumber" ,
295
295
Type : "number" ,
296
296
Value : "hi" ,
297
- Error : regexp .MustCompile ("parse value hi as int " ),
297
+ Error : regexp .MustCompile ("is not a number " ),
298
298
}, {
299
299
Name : "NumberBelowMin" ,
300
300
Type : "number" ,
@@ -307,6 +307,11 @@ func TestValueValidatesType(t *testing.T) {
307
307
Value : "1" ,
308
308
Max : 0 ,
309
309
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" ),
310
315
}} {
311
316
tc := tc
312
317
t .Run (tc .Name , func (t * testing.T ) {
@@ -318,7 +323,7 @@ func TestValueValidatesType(t *testing.T) {
318
323
}
319
324
err := v .Valid (tc .Type , tc .Value )
320
325
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 () )
322
327
}
323
328
})
324
329
}
You can’t perform that action at this time.
0 commit comments