@@ -157,12 +157,14 @@ func parameterDataSource() *schema.Resource {
157
157
// Validate options
158
158
_ , parameter .FormType , err = ValidateFormType (parameter .Type , len (parameter .Option ), parameter .FormType )
159
159
if err != nil {
160
- return singleDiag (diag.Diagnostic {
161
- Severity : diag .Error ,
162
- Summary : "Invalid form_type for parameter" ,
163
- Detail : err .Error (),
164
- AttributePath : cty.Path {cty.GetAttrStep {Name : "form_type" }},
165
- })
160
+ return diag.Diagnostics {
161
+ {
162
+ Severity : diag .Error ,
163
+ Summary : "Invalid form_type for parameter" ,
164
+ Detail : err .Error (),
165
+ AttributePath : cty.Path {cty.GetAttrStep {Name : "form_type" }},
166
+ },
167
+ }
166
168
}
167
169
// Set the form_type back in case the value was changed.
168
170
// Eg via a default. If a user does not specify, a default value
@@ -417,12 +419,14 @@ func (v *Parameter) Valid() diag.Diagnostics {
417
419
// should be used for the value type, and optionType for options.
418
420
optionType , _ , err := ValidateFormType (v .Type , len (v .Option ), v .FormType )
419
421
if err != nil {
420
- return singleDiag (diag.Diagnostic {
421
- Severity : diag .Error ,
422
- Summary : "Invalid form_type for parameter" ,
423
- Detail : err .Error (),
424
- AttributePath : cty.Path {cty.GetAttrStep {Name : "form_type" }},
425
- })
422
+ return diag.Diagnostics {
423
+ {
424
+ Severity : diag .Error ,
425
+ Summary : "Invalid form_type for parameter" ,
426
+ Detail : err .Error (),
427
+ AttributePath : cty.Path {cty.GetAttrStep {Name : "form_type" }},
428
+ },
429
+ }
426
430
}
427
431
428
432
optionNames := map [string ]interface {}{}
@@ -431,19 +435,22 @@ func (v *Parameter) Valid() diag.Diagnostics {
431
435
for _ , option := range v .Option {
432
436
_ , exists := optionNames [option .Name ]
433
437
if exists {
434
- return singleDiag ( diag.Diagnostic {
438
+ return diag.Diagnostics { {
435
439
Severity : diag .Error ,
436
440
Summary : "Option names must be unique." ,
437
441
Detail : fmt .Sprintf ("multiple options found with the same name %q" , option .Name ),
438
- })
442
+ },
443
+ }
439
444
}
440
445
_ , exists = optionValues [option .Value ]
441
446
if exists {
442
- return singleDiag (diag.Diagnostic {
443
- Severity : diag .Error ,
444
- Summary : "Option values must be unique." ,
445
- Detail : fmt .Sprintf ("multiple options found with the same value %q" , option .Value ),
446
- })
447
+ return diag.Diagnostics {
448
+ {
449
+ Severity : diag .Error ,
450
+ Summary : "Option values must be unique." ,
451
+ Detail : fmt .Sprintf ("multiple options found with the same value %q" , option .Value ),
452
+ },
453
+ }
447
454
}
448
455
diags := valueIsType (optionType , option .Value , cty.Path {})
449
456
if diags .HasError () {
@@ -473,25 +480,29 @@ func (v *Parameter) Valid() diag.Diagnostics {
473
480
}
474
481
475
482
if len (missing ) > 0 {
476
- return singleDiag (diag.Diagnostic {
477
- Severity : diag .Error ,
478
- Summary : "Default values must be a valid option" ,
479
- Detail : fmt .Sprintf (
480
- "default value %q is not a valid option, values %q are missing from the options" ,
481
- v .Default , strings .Join (missing , ", " ),
482
- ),
483
- AttributePath : cty.Path {cty.GetAttrStep {Name : "default" }},
484
- })
483
+ return diag.Diagnostics {
484
+ {
485
+ Severity : diag .Error ,
486
+ Summary : "Default values must be a valid option" ,
487
+ Detail : fmt .Sprintf (
488
+ "default value %q is not a valid option, values %q are missing from the options" ,
489
+ v .Default , strings .Join (missing , ", " ),
490
+ ),
491
+ AttributePath : cty.Path {cty.GetAttrStep {Name : "default" }},
492
+ },
493
+ }
485
494
}
486
495
} else {
487
496
_ , defaultIsValid := optionValues [v .Default ]
488
497
if ! defaultIsValid {
489
- return singleDiag (diag.Diagnostic {
490
- Severity : diag .Error ,
491
- Summary : "Default value must be a valid option" ,
492
- Detail : fmt .Sprintf ("the value %q must be defined as one of options" , v .Default ),
493
- AttributePath : cty.Path {cty.GetAttrStep {Name : "default" }},
494
- })
498
+ return diag.Diagnostics {
499
+ {
500
+ Severity : diag .Error ,
501
+ Summary : "Default value must be a valid option" ,
502
+ Detail : fmt .Sprintf ("the value %q must be defined as one of options" , v .Default ),
503
+ AttributePath : cty.Path {cty.GetAttrStep {Name : "default" }},
504
+ },
505
+ }
495
506
}
496
507
}
497
508
}
@@ -563,12 +574,14 @@ func valueIsListString(value string, path cty.Path) ([]string, diag.Diagnostics)
563
574
var items []string
564
575
err := json .Unmarshal ([]byte (value ), & items )
565
576
if err != nil {
566
- return nil , singleDiag (diag.Diagnostic {
567
- Severity : diag .Error ,
568
- Summary : fmt .Sprintf ("When using list(string) type, value must be a json encoded list of strings" ),
569
- Detail : fmt .Sprintf ("value %q is not a valid list of strings" , value ),
570
- AttributePath : path ,
571
- })
577
+ return nil , diag.Diagnostics {
578
+ {
579
+ Severity : diag .Error ,
580
+ Summary : fmt .Sprintf ("When using list(string) type, value must be a json encoded list of strings" ),
581
+ Detail : fmt .Sprintf ("value %q is not a valid list of strings" , value ),
582
+ AttributePath : path ,
583
+ },
584
+ }
572
585
}
573
586
return items , nil
574
587
}
@@ -600,7 +613,3 @@ func (v *Validation) errorRendered(value string) error {
600
613
"{value}" , value )
601
614
return xerrors .Errorf (r .Replace (v .Error ))
602
615
}
603
-
604
- func singleDiag (diagnostic diag.Diagnostic ) diag.Diagnostics {
605
- return diag.Diagnostics {diagnostic }
606
- }
0 commit comments