@@ -28,8 +28,11 @@ type Option struct {
28
28
}
29
29
30
30
type 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
+
33
36
Monotonic string
34
37
35
38
Regex string
@@ -288,11 +291,21 @@ func parameterDataSource() *schema.Resource {
288
291
Optional : true ,
289
292
Description : "The minimum of a number parameter." ,
290
293
},
294
+ "min_disabled" : {
295
+ Type : schema .TypeBool ,
296
+ Computed : true ,
297
+ Description : "Helper field to check if min is present" ,
298
+ },
291
299
"max" : {
292
300
Type : schema .TypeInt ,
293
301
Optional : true ,
294
302
Description : "The maximum of a number parameter." ,
295
303
},
304
+ "max_disabled" : {
305
+ Type : schema .TypeBool ,
306
+ Computed : true ,
307
+ Description : "Helper field to check if max is present" ,
308
+ },
296
309
"monotonic" : {
297
310
Type : schema .TypeString ,
298
311
Optional : true ,
@@ -363,13 +376,8 @@ func fixValidationResourceData(rawConfig cty.Value, validation interface{}) (int
363
376
return nil , xerrors .New ("validation rule should be a map" )
364
377
}
365
378
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 ()
373
381
return vArr , nil
374
382
}
375
383
@@ -401,10 +409,10 @@ func valueIsType(typ, value string) diag.Diagnostics {
401
409
402
410
func (v * Validation ) Valid (typ , value string ) error {
403
411
if typ != "number" {
404
- if v . Min != nil {
412
+ if ! v . MinDisabled {
405
413
return fmt .Errorf ("a min cannot be specified for a %s type" , typ )
406
414
}
407
- if v . Max != nil {
415
+ if ! v . MaxDisabled {
408
416
return fmt .Errorf ("a max cannot be specified for a %s type" , typ )
409
417
}
410
418
}
@@ -437,11 +445,11 @@ func (v *Validation) Valid(typ, value string) error {
437
445
if err != nil {
438
446
return fmt .Errorf ("value %q is not a number" , value )
439
447
}
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 )
442
450
}
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 )
445
453
}
446
454
if v .Monotonic != "" && v .Monotonic != ValidationMonotonicIncreasing && v .Monotonic != ValidationMonotonicDecreasing {
447
455
return fmt .Errorf ("number monotonicity can be either %q or %q" , ValidationMonotonicIncreasing , ValidationMonotonicDecreasing )
0 commit comments