77 "context"
88 "fmt"
99
10+ "github.com/hashicorp/terraform-plugin-framework/diag"
1011 "github.com/hashicorp/terraform-plugin-framework/function"
1112 "github.com/hashicorp/terraform-plugin-framework/schema/validator"
1213
@@ -30,7 +31,28 @@ func (validator atMostValidator) MarkdownDescription(ctx context.Context) string
3031}
3132
3233func (v atMostValidator ) ValidateInt64 (ctx context.Context , request validator.Int64Request , response * validator.Int64Response ) {
33- if request .ConfigValue .IsNull () || request .ConfigValue .IsUnknown () {
34+ if request .ConfigValue .IsNull () {
35+ return
36+ }
37+
38+ if request .ConfigValue .IsUnknown () {
39+ // Check if there is a lower bound refinement, and if that lower bound indicates the eventual value will be invalid
40+ if lowerRefn , ok := request .ConfigValue .LowerBoundRefinement (); ok {
41+ if lowerRefn .IsInclusive () && lowerRefn .LowerBound () > v .max {
42+ response .Diagnostics .Append (diag .NewAttributeErrorDiagnostic (
43+ request .Path ,
44+ "Invalid Attribute Value" ,
45+ // TODO: improve error messaging?
46+ fmt .Sprintf ("Attribute %s %s, got an unknown value that will be greater than: %d" , request .Path , v .Description (ctx ), lowerRefn .LowerBound ()),
47+ ))
48+ } else if ! lowerRefn .IsInclusive () && lowerRefn .LowerBound () >= v .max {
49+ response .Diagnostics .Append (diag .NewAttributeErrorDiagnostic (
50+ request .Path ,
51+ "Invalid Attribute Value" ,
52+ fmt .Sprintf ("Attribute %s %s, got an unknown value that will be at least: %d" , request .Path , v .Description (ctx ), lowerRefn .LowerBound ()),
53+ ))
54+ }
55+ }
3456 return
3557 }
3658
@@ -44,7 +66,25 @@ func (v atMostValidator) ValidateInt64(ctx context.Context, request validator.In
4466}
4567
4668func (v atMostValidator ) ValidateParameterInt64 (ctx context.Context , request function.Int64ParameterValidatorRequest , response * function.Int64ParameterValidatorResponse ) {
47- if request .Value .IsNull () || request .Value .IsUnknown () {
69+ if request .Value .IsNull () {
70+ return
71+ }
72+
73+ if request .Value .IsUnknown () {
74+ // Check if there is a lower bound refinement, and if that lower bound indicates the eventual value will be invalid
75+ if lowerRefn , ok := request .Value .LowerBoundRefinement (); ok {
76+ if lowerRefn .IsInclusive () && lowerRefn .LowerBound () > v .max {
77+ response .Error = function .NewArgumentFuncError (
78+ request .ArgumentPosition ,
79+ fmt .Sprintf ("Invalid Parameter Value: %s, got an unknown value that will be greater than: %d" , v .Description (ctx ), lowerRefn .LowerBound ()),
80+ )
81+ } else if ! lowerRefn .IsInclusive () && lowerRefn .LowerBound () >= v .max {
82+ response .Error = function .NewArgumentFuncError (
83+ request .ArgumentPosition ,
84+ fmt .Sprintf ("Invalid Parameter Value: %s, got an unknown value that will be at least: %d" , v .Description (ctx ), lowerRefn .LowerBound ()),
85+ )
86+ }
87+ }
4888 return
4989 }
5090
0 commit comments