6
6
"strings"
7
7
8
8
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
9
-
10
- "github.com/hashicorp/terraform-plugin-framework-validators/validatordiag"
11
9
)
12
10
13
11
var _ tfsdk.AttributeValidator = valuesAreValidator {}
@@ -39,14 +37,16 @@ func (v valuesAreValidator) Validate(ctx context.Context, req tfsdk.ValidateAttr
39
37
return
40
38
}
41
39
42
- for k , elem := range elems {
40
+ for _ , elem := range elems {
43
41
value , err := elem .ToTerraformValue (ctx )
44
42
if err != nil {
45
- resp .Diagnostics .Append (validatordiag .AttributeValueTerraformValueDiagnostic (
46
- req .AttributePath ,
47
- fmt .Sprintf ("element at index: %d cannot be converted to Terraform value" , k ),
48
- err .Error (),
49
- ))
43
+ resp .Diagnostics .AddError (
44
+ "Attribute Conversion Error During Set Element Validation" ,
45
+ "An unexpected error was encountered when handling the a Set element. " +
46
+ "This is always an issue in terraform-plugin-framework used to implement the provider and should be reported to the provider developers.\n \n " +
47
+ "Please report this to the provider developer:\n \n " +
48
+ "Attribute Conversion Error During Set Element Validation." ,
49
+ )
50
50
return
51
51
}
52
52
@@ -58,13 +58,17 @@ func (v valuesAreValidator) Validate(ctx context.Context, req tfsdk.ValidateAttr
58
58
59
59
for _ , validator := range v .valueValidators {
60
60
validator .Validate (ctx , request , resp )
61
- if resp .Diagnostics .HasError () {
62
- return
63
- }
64
61
}
65
62
}
66
63
}
67
64
65
+ // ValuesAre returns an AttributeValidator which ensures that any configured
66
+ // attribute value:
67
+ //
68
+ // - Is a Set.
69
+ // - Contains Set elements, each of which validate against each value validator.
70
+ //
71
+ // Null (unconfigured) and unknown (known after apply) values are skipped.
68
72
func ValuesAre (valueValidators ... tfsdk.AttributeValidator ) tfsdk.AttributeValidator {
69
73
return valuesAreValidator {
70
74
valueValidators : valueValidators ,
0 commit comments