@@ -51,7 +51,7 @@ type Parameter struct {
51
51
Name string
52
52
DisplayName string `mapstructure:"display_name"`
53
53
Description string
54
- Type string
54
+ Type OptionType
55
55
FormType ParameterFormType
56
56
Mutable bool
57
57
Default string
@@ -154,7 +154,7 @@ func parameterDataSource() *schema.Resource {
154
154
}
155
155
156
156
// Validate options
157
- var optionType string
157
+ var optionType OptionType
158
158
optionType , parameter .FormType , err = ValidateFormType (parameter .Type , len (parameter .Option ), parameter .FormType )
159
159
if err != nil {
160
160
return diag .FromErr (err )
@@ -182,7 +182,7 @@ func parameterDataSource() *schema.Resource {
182
182
}
183
183
184
184
if parameter .Default != "" {
185
- if parameter .Type == "list(string)" && optionType == "string" {
185
+ if parameter .Type == OptionTypeListString && optionType == OptionTypeString {
186
186
// If the type is list(string) and optionType is string, we have
187
187
// to ensure all elements of the default exist as options.
188
188
var defaultValues []string
@@ -241,7 +241,7 @@ func parameterDataSource() *schema.Resource {
241
241
Type : schema .TypeString ,
242
242
Default : "string" ,
243
243
Optional : true ,
244
- ValidateFunc : validation .StringInSlice ([] string { "number" , "string" , "bool" , "list(string)" } , false ),
244
+ ValidateFunc : validation .StringInSlice (toStrings ( OptionTypes ()) , false ),
245
245
Description : "The type of this parameter. Must be one of: `\" number\" `, `\" string\" `, `\" bool\" `, or `\" list(string)\" `." ,
246
246
},
247
247
"form_type" : {
@@ -431,38 +431,38 @@ func fixValidationResourceData(rawConfig cty.Value, validation interface{}) (int
431
431
return vArr , nil
432
432
}
433
433
434
- func valueIsType (typ , value string ) diag.Diagnostics {
434
+ func valueIsType (typ OptionType , value string ) diag.Diagnostics {
435
435
switch typ {
436
- case "number" :
436
+ case OptionTypeNumber :
437
437
_ , err := strconv .ParseFloat (value , 64 )
438
438
if err != nil {
439
439
return diag .Errorf ("%q is not a number" , value )
440
440
}
441
- case "bool" :
441
+ case OptionTypeBoolean :
442
442
_ , err := strconv .ParseBool (value )
443
443
if err != nil {
444
444
return diag .Errorf ("%q is not a bool" , value )
445
445
}
446
- case "list(string)" :
446
+ case OptionTypeListString :
447
447
var items []string
448
448
err := json .Unmarshal ([]byte (value ), & items )
449
449
if err != nil {
450
450
return diag .Errorf ("%q is not an array of strings" , value )
451
451
}
452
- case "string" :
452
+ case OptionTypeString :
453
453
// Anything is a string!
454
454
default :
455
455
return diag .Errorf ("invalid type %q" , typ )
456
456
}
457
457
return nil
458
458
}
459
459
460
- func (v * Validation ) Valid (typ , value string ) error {
460
+ func (v * Validation ) Valid (typ OptionType , value string ) error {
461
461
if v .Invalid {
462
462
return v .errorRendered (value )
463
463
}
464
464
465
- if typ != "number" {
465
+ if typ != OptionTypeNumber {
466
466
if ! v .MinDisabled {
467
467
return fmt .Errorf ("a min cannot be specified for a %s type" , typ )
468
468
}
@@ -473,16 +473,16 @@ func (v *Validation) Valid(typ, value string) error {
473
473
return fmt .Errorf ("monotonic validation can only be specified for number types, not %s types" , typ )
474
474
}
475
475
}
476
- if typ != "string" && v .Regex != "" {
476
+ if typ != OptionTypeString && v .Regex != "" {
477
477
return fmt .Errorf ("a regex cannot be specified for a %s type" , typ )
478
478
}
479
479
switch typ {
480
- case "bool" :
480
+ case OptionTypeBoolean :
481
481
if value != "true" && value != "false" {
482
482
return fmt .Errorf (`boolean value can be either "true" or "false"` )
483
483
}
484
484
return nil
485
- case "string" :
485
+ case OptionTypeString :
486
486
if v .Regex == "" {
487
487
return nil
488
488
}
@@ -497,7 +497,7 @@ func (v *Validation) Valid(typ, value string) error {
497
497
if ! matched {
498
498
return fmt .Errorf ("%s (value %q does not match %q)" , v .Error , value , regex )
499
499
}
500
- case "number" :
500
+ case OptionTypeNumber :
501
501
num , err := strconv .Atoi (value )
502
502
if err != nil {
503
503
return takeFirstError (v .errorRendered (value ), fmt .Errorf ("value %q is not a number" , value ))
@@ -511,7 +511,7 @@ func (v *Validation) Valid(typ, value string) error {
511
511
if v .Monotonic != "" && v .Monotonic != ValidationMonotonicIncreasing && v .Monotonic != ValidationMonotonicDecreasing {
512
512
return fmt .Errorf ("number monotonicity can be either %q or %q" , ValidationMonotonicIncreasing , ValidationMonotonicDecreasing )
513
513
}
514
- case "list(string)" :
514
+ case OptionTypeListString :
515
515
var listOfStrings []string
516
516
err := json .Unmarshal ([]byte (value ), & listOfStrings )
517
517
if err != nil {
0 commit comments