@@ -51,7 +51,7 @@ type Parameter struct {
5151 Name string
5252 DisplayName string `mapstructure:"display_name"`
5353 Description string
54- Type string
54+ Type OptionType
5555 FormType ParameterFormType
5656 Mutable bool
5757 Default string
@@ -154,7 +154,7 @@ func parameterDataSource() *schema.Resource {
154154 }
155155
156156 // Validate options
157- var optionType string
157+ var optionType OptionType
158158 optionType , parameter .FormType , err = ValidateFormType (parameter .Type , len (parameter .Option ), parameter .FormType )
159159 if err != nil {
160160 return diag .FromErr (err )
@@ -182,7 +182,7 @@ func parameterDataSource() *schema.Resource {
182182 }
183183
184184 if parameter .Default != "" {
185- if parameter .Type == "list(string)" && optionType == "string" {
185+ if parameter .Type == OptionTypeListString && optionType == OptionTypeString {
186186 // If the type is list(string) and optionType is string, we have
187187 // to ensure all elements of the default exist as options.
188188 var defaultValues []string
@@ -241,7 +241,7 @@ func parameterDataSource() *schema.Resource {
241241 Type : schema .TypeString ,
242242 Default : "string" ,
243243 Optional : true ,
244- ValidateFunc : validation .StringInSlice ([] string { "number" , "string" , "bool" , "list(string)" } , false ),
244+ ValidateFunc : validation .StringInSlice (toStrings ( OptionTypes ()) , false ),
245245 Description : "The type of this parameter. Must be one of: `\" number\" `, `\" string\" `, `\" bool\" `, or `\" list(string)\" `." ,
246246 },
247247 "form_type" : {
@@ -431,38 +431,38 @@ func fixValidationResourceData(rawConfig cty.Value, validation interface{}) (int
431431 return vArr , nil
432432}
433433
434- func valueIsType (typ , value string ) diag.Diagnostics {
434+ func valueIsType (typ OptionType , value string ) diag.Diagnostics {
435435 switch typ {
436- case "number" :
436+ case OptionTypeNumber :
437437 _ , err := strconv .ParseFloat (value , 64 )
438438 if err != nil {
439439 return diag .Errorf ("%q is not a number" , value )
440440 }
441- case "bool" :
441+ case OptionTypeBoolean :
442442 _ , err := strconv .ParseBool (value )
443443 if err != nil {
444444 return diag .Errorf ("%q is not a bool" , value )
445445 }
446- case "list(string)" :
446+ case OptionTypeListString :
447447 var items []string
448448 err := json .Unmarshal ([]byte (value ), & items )
449449 if err != nil {
450450 return diag .Errorf ("%q is not an array of strings" , value )
451451 }
452- case "string" :
452+ case OptionTypeString :
453453 // Anything is a string!
454454 default :
455455 return diag .Errorf ("invalid type %q" , typ )
456456 }
457457 return nil
458458}
459459
460- func (v * Validation ) Valid (typ , value string ) error {
460+ func (v * Validation ) Valid (typ OptionType , value string ) error {
461461 if v .Invalid {
462462 return v .errorRendered (value )
463463 }
464464
465- if typ != "number" {
465+ if typ != OptionTypeNumber {
466466 if ! v .MinDisabled {
467467 return fmt .Errorf ("a min cannot be specified for a %s type" , typ )
468468 }
@@ -473,16 +473,16 @@ func (v *Validation) Valid(typ, value string) error {
473473 return fmt .Errorf ("monotonic validation can only be specified for number types, not %s types" , typ )
474474 }
475475 }
476- if typ != "string" && v .Regex != "" {
476+ if typ != OptionTypeString && v .Regex != "" {
477477 return fmt .Errorf ("a regex cannot be specified for a %s type" , typ )
478478 }
479479 switch typ {
480- case "bool" :
480+ case OptionTypeBoolean :
481481 if value != "true" && value != "false" {
482482 return fmt .Errorf (`boolean value can be either "true" or "false"` )
483483 }
484484 return nil
485- case "string" :
485+ case OptionTypeString :
486486 if v .Regex == "" {
487487 return nil
488488 }
@@ -497,7 +497,7 @@ func (v *Validation) Valid(typ, value string) error {
497497 if ! matched {
498498 return fmt .Errorf ("%s (value %q does not match %q)" , v .Error , value , regex )
499499 }
500- case "number" :
500+ case OptionTypeNumber :
501501 num , err := strconv .Atoi (value )
502502 if err != nil {
503503 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 {
511511 if v .Monotonic != "" && v .Monotonic != ValidationMonotonicIncreasing && v .Monotonic != ValidationMonotonicDecreasing {
512512 return fmt .Errorf ("number monotonicity can be either %q or %q" , ValidationMonotonicIncreasing , ValidationMonotonicDecreasing )
513513 }
514- case "list(string)" :
514+ case OptionTypeListString :
515515 var listOfStrings []string
516516 err := json .Unmarshal ([]byte (value ), & listOfStrings )
517517 if err != nil {
0 commit comments