@@ -28,8 +28,11 @@ type Option struct {
2828}
2929
3030type Validation struct {
31- Min * int
32- Max * int
31+ Min int
32+ MinDisabled bool `mapstructure:"min_disabled"`
33+ Max int
34+ MaxDisabled bool `mapstructure:"max_disabled"`
35+
3336 Monotonic string
3437
3538 Regex string
@@ -288,11 +291,21 @@ func parameterDataSource() *schema.Resource {
288291 Optional : true ,
289292 Description : "The minimum of a number parameter." ,
290293 },
294+ "min_disabled" : {
295+ Type : schema .TypeBool ,
296+ Computed : true ,
297+ Description : "Helper field to check if min is present" ,
298+ },
291299 "max" : {
292300 Type : schema .TypeInt ,
293301 Optional : true ,
294302 Description : "The maximum of a number parameter." ,
295303 },
304+ "max_disabled" : {
305+ Type : schema .TypeBool ,
306+ Computed : true ,
307+ Description : "Helper field to check if max is present" ,
308+ },
296309 "monotonic" : {
297310 Type : schema .TypeString ,
298311 Optional : true ,
@@ -363,13 +376,8 @@ func fixValidationResourceData(rawConfig cty.Value, validation interface{}) (int
363376 return nil , xerrors .New ("validation rule should be a map" )
364377 }
365378
366- // Fix the resource data
367- if rawValidationRule ["min" ].IsNull () {
368- validationRule ["min" ] = nil
369- }
370- if rawValidationRule ["max" ].IsNull () {
371- validationRule ["max" ] = nil
372- }
379+ validationRule ["min_disabled" ] = rawValidationRule ["min" ].IsNull ()
380+ validationRule ["max_disabled" ] = rawValidationRule ["max" ].IsNull ()
373381 return vArr , nil
374382}
375383
@@ -401,10 +409,10 @@ func valueIsType(typ, value string) diag.Diagnostics {
401409
402410func (v * Validation ) Valid (typ , value string ) error {
403411 if typ != "number" {
404- if v . Min != nil {
412+ if ! v . MinDisabled {
405413 return fmt .Errorf ("a min cannot be specified for a %s type" , typ )
406414 }
407- if v . Max != nil {
415+ if ! v . MaxDisabled {
408416 return fmt .Errorf ("a max cannot be specified for a %s type" , typ )
409417 }
410418 }
@@ -437,11 +445,11 @@ func (v *Validation) Valid(typ, value string) error {
437445 if err != nil {
438446 return fmt .Errorf ("value %q is not a number" , value )
439447 }
440- if v . Min != nil && num < * v .Min {
441- return fmt .Errorf ("value %d is less than the minimum %d" , num , * v .Min )
448+ if ! v . MinDisabled && num < v .Min {
449+ return fmt .Errorf ("value %d is less than the minimum %d" , num , v .Min )
442450 }
443- if v . Max != nil && num > * v .Max {
444- return fmt .Errorf ("value %d is more than the maximum %d" , num , * v .Max )
451+ if ! v . MaxDisabled && num > v .Max {
452+ return fmt .Errorf ("value %d is more than the maximum %d" , num , v .Max )
445453 }
446454 if v .Monotonic != "" && v .Monotonic != ValidationMonotonicIncreasing && v .Monotonic != ValidationMonotonicDecreasing {
447455 return fmt .Errorf ("number monotonicity can be either %q or %q" , ValidationMonotonicIncreasing , ValidationMonotonicDecreasing )
0 commit comments