@@ -50,7 +50,6 @@ const (
50
50
)
51
51
52
52
type Parameter struct {
53
- Value string
54
53
Name string
55
54
DisplayName string `mapstructure:"display_name"`
56
55
Description string
@@ -86,7 +85,6 @@ func parameterDataSource() *schema.Resource {
86
85
87
86
var parameter Parameter
88
87
err = mapstructure .Decode (struct {
89
- Value interface {}
90
88
Name interface {}
91
89
DisplayName interface {}
92
90
Description interface {}
@@ -101,7 +99,6 @@ func parameterDataSource() *schema.Resource {
101
99
Order interface {}
102
100
Ephemeral interface {}
103
101
}{
104
- Value :rd .Get ("value" ),
105
102
Name :rd .Get ("name" ),
106
103
DisplayName :rd .Get ("display_name" ),
107
104
Description :rd .Get ("description" ),
@@ -126,14 +123,7 @@ func parameterDataSource() *schema.Resource {
126
123
if err != nil {
127
124
return diag .Errorf ("decode parameter: %s" ,err )
128
125
}
129
- var value string
130
- if parameter .Default != "" {
131
- err := valueIsType (parameter .Type ,parameter .Default ,defaultValuePath )
132
- if err != nil {
133
- return err
134
- }
135
- value = parameter .Default
136
- }
126
+ value := parameter .Default
137
127
envValue ,ok := os .LookupEnv (ParameterEnvironmentVariable (parameter .Name ))
138
128
if ok {
139
129
value = envValue
@@ -381,27 +371,27 @@ func fixValidationResourceData(rawConfig cty.Value, validation interface{}) (int
381
371
return vArr ,nil
382
372
}
383
373
384
- func valueIsType (typ OptionType ,value string , attrPath cty. Path ) diag. Diagnostics {
374
+ func valueIsType (typ OptionType ,value string ) error {
385
375
switch typ {
386
376
case OptionTypeNumber :
387
377
_ ,err := strconv .ParseFloat (value ,64 )
388
378
if err != nil {
389
- return diag .Errorf ("%q is not a number" ,value )
379
+ return fmt .Errorf ("%q is not a number" ,value )
390
380
}
391
381
case OptionTypeBoolean :
392
382
_ ,err := strconv .ParseBool (value )
393
383
if err != nil {
394
- return diag .Errorf ("%q is not a bool" ,value )
384
+ return fmt .Errorf ("%q is not a bool" ,value )
395
385
}
396
386
case OptionTypeListString :
397
- _ ,diags := valueIsListString (value , attrPath )
398
- if diags . HasError () {
399
- return diags
387
+ _ ,err := valueIsListString (value )
388
+ if err != nil {
389
+ return err
400
390
}
401
391
case OptionTypeString :
402
392
// Anything is a string!
403
393
default :
404
- return diag .Errorf ("invalid type %q" ,typ )
394
+ return fmt .Errorf ("invalid type %q" ,typ )
405
395
}
406
396
return nil
407
397
}
@@ -447,9 +437,15 @@ func (v *Parameter) Valid(value string) diag.Diagnostics {
447
437
},
448
438
}
449
439
}
450
- diags := valueIsType (optionType ,option .Value , cty.Path {})
451
- if diags .HasError () {
452
- return diags
440
+ err = valueIsType (optionType ,option .Value )
441
+ if err != nil {
442
+ return diag.Diagnostics {
443
+ {
444
+ Severity :diag .Error ,
445
+ Summary :fmt .Sprintf ("Option %q with value=%q is not of type %q" ,option .Name ,option .Value ,optionType ),
446
+ Detail :err .Error (),
447
+ },
448
+ }
453
449
}
454
450
optionValues [option .Value ]= nil
455
451
optionNames [option .Name ]= nil
@@ -461,6 +457,18 @@ func (v *Parameter) Valid(value string) diag.Diagnostics {
461
457
462
458
// Validate the default value
463
459
if v .Default != "" {
460
+ err := valueIsType (v .Type ,v .Default )
461
+ if err != nil {
462
+ return diag.Diagnostics {
463
+ {
464
+ Severity :diag .Error ,
465
+ Summary :fmt .Sprintf ("Default value is not of type %q" ,v .Type ),
466
+ Detail :err .Error (),
467
+ AttributePath :defaultValuePath ,
468
+ },
469
+ }
470
+ }
471
+
464
472
d := v .validValue (v .Default ,optionType ,optionValues ,defaultValuePath )
465
473
if d .HasError () {
466
474
return d
@@ -473,6 +481,17 @@ func (v *Parameter) Valid(value string) diag.Diagnostics {
473
481
return d
474
482
}
475
483
484
+ err = valueIsType (v .Type ,value )
485
+ if err != nil {
486
+ return diag.Diagnostics {
487
+ {
488
+ Severity :diag .Error ,
489
+ Summary :fmt .Sprintf ("Parameter value is not of type %q" ,v .Type ),
490
+ Detail :err .Error (),
491
+ },
492
+ }
493
+ }
494
+
476
495
return nil
477
496
}
478
497
@@ -488,9 +507,16 @@ func (v *Parameter) validValue(value string, optionType OptionType, optionValues
488
507
if v .Type == OptionTypeListString && optionType == OptionTypeString {
489
508
// If the type is list(string) and optionType is string, we have
490
509
// to ensure all elements of the default exist as options.
491
- listValues ,diags := valueIsListString (value ,defaultValuePath )
492
- if diags .HasError () {
493
- return diags
510
+ listValues ,err := valueIsListString (value )
511
+ if err != nil {
512
+ return diag.Diagnostics {
513
+ {
514
+ Severity :diag .Error ,
515
+ Summary :"When using list(string) type, value must be a json encoded list of strings" ,
516
+ Detail :err .Error (),
517
+ AttributePath :defaultValuePath ,
518
+ },
519
+ }
494
520
}
495
521
496
522
// missing is used to construct a more helpful error message
@@ -608,18 +634,11 @@ func (v *Validation) Valid(typ OptionType, value string) error {
608
634
return nil
609
635
}
610
636
611
- func valueIsListString (value string , path cty. Path ) ([]string ,diag. Diagnostics ) {
637
+ func valueIsListString (value string ) ([]string ,error ) {
612
638
var items []string
613
639
err := json .Unmarshal ([]byte (value ),& items )
614
640
if err != nil {
615
- return nil , diag.Diagnostics {
616
- {
617
- Severity :diag .Error ,
618
- Summary :"When using list(string) type, value must be a json encoded list of strings" ,
619
- Detail :fmt .Sprintf ("value %q is not a valid list of strings" ,value ),
620
- AttributePath :path ,
621
- },
622
- }
641
+ return nil ,fmt .Errorf ("value %q is not a valid list of strings" ,value )
623
642
}
624
643
return items ,nil
625
644
}