@@ -507,6 +507,44 @@ filter_attribute_is_not_value = func(resources, attr, value, prtmsg) {
507
507
return {"resources":violators,"messages":messages}
508
508
}
509
509
510
+ ### filter_attribute_was_not_value ###
511
+ # Filter a list of resources to those with a specified
512
+ # attribute (attr) that did not have a given value.
513
+ # Resources should be derived by applying filters to tfplan.resource_changes.
514
+ # Set prtmsg to `true` (without quotes) if you want to print violation messages.
515
+ # If you want to match null, set value to "null".
516
+ # Note that it this function passes `change.actions.before` instead of `rc`
517
+ # to the evaluate_attribute() function which converts `rc` to `rc.change.after`.
518
+ filter_attribute_was_not_value = func(resources, attr, value, prtmsg) {
519
+ violators = {}
520
+ messages = {}
521
+ for resources as address, rc {
522
+ v = evaluate_attribute(rc.change.before, attr) else null
523
+ if v is null {
524
+ # Add the resource and a warning message to the violators list
525
+ message = to_string(address) + " had " + to_string(attr) +
526
+ " that was null or undefined. " + "It was supposed to be " +
527
+ to_string(value)
528
+ violators[address] = rc
529
+ messages[address] = message
530
+ if prtmsg {
531
+ print(message)
532
+ }
533
+ } else if v is not value {
534
+ # Add the resource and a warning message to the violators list
535
+ message = to_string(address) + " had " + to_string(attr) + " with value " +
536
+ to_string(v) + " that was not equal to " + to_string(value)
537
+ violators[address] = rc
538
+ messages[address] = message
539
+ if prtmsg {
540
+ print(message)
541
+ }
542
+ }
543
+ }
544
+ return {"resources":violators,"messages":messages}
545
+ }
546
+
547
+
510
548
### filter_attribute_is_value ###
511
549
# Filter a list of resources to those with a specified
512
550
# attribute (attr) that has a given value.
@@ -535,6 +573,36 @@ filter_attribute_is_value = func(resources, attr, value, prtmsg) {
535
573
return {"resources":violators,"messages":messages}
536
574
}
537
575
576
+ ### filter_attribute_was_value ###
577
+ # Filter a list of resources to those with a specified
578
+ # attribute (attr) that had a given value.
579
+ # Resources should be derived by applying filters to tfplan.resource_changes.
580
+ # Set prtmsg to `true` (without quotes) if you want to print violation messages.
581
+ # If you want to match null, set value to "null".
582
+ # Note that it this function passes `change.actions.before` instead of `rc`
583
+ # to the evaluate_attribute() function which converts `rc` to `rc.change.after`.
584
+ filter_attribute_was_value = func(resources, attr, value, prtmsg) {
585
+ violators = {}
586
+ messages = {}
587
+ for resources as address, rc {
588
+ v = evaluate_attribute(rc.change.before, attr) else null
589
+ if v is null {
590
+ v = "null"
591
+ }
592
+ if v is value {
593
+ # Add the resource and a warning message to the violators list
594
+ message = to_string(address) + " had " + to_string(attr) + " with value " +
595
+ to_string(v) + " that was not allowed."
596
+ violators[address] = rc
597
+ messages[address] = message
598
+ if prtmsg {
599
+ print(message)
600
+ }
601
+ }
602
+ }
603
+ return {"resources":violators,"messages":messages}
604
+ }
605
+
538
606
### filter_attribute_greater_than_value ###
539
607
# Filter a list of resources to those with a specified
540
608
# attribute (attr) that is greater than a given numeric value.
0 commit comments