region group plan gate: preserve last applied size baseline
Refuse planned ASG sizes below the same address drift row before value so a config shrink cannot hide behind Standby drift. Keep the existing comparison against refreshed live sizes and allow restoration to the last applied capacity.
2 files changed,
+29
−0
scripts/check-region-group-plan.py+11 −0scripts/check_region_group_plan_test.py+18 −0
CI failed — run details
diff --git a/scripts/check-region-group-plan.py b/scripts/check-region-group-plan.py| index 488bb23d0..9f24d8424 100755 |
| --- a/scripts/check-region-group-plan.py |
| +++ b/scripts/check-region-group-plan.py |
| @@ -466,6 +466,10 @@ def check(document, entries, manifest): |
| rows = changes(document) |
| groups = group_modules(document, rows) |
| parsed = [parse_resource(row, groups) for row in rows] |
| + drift_before = {} |
| + for address, kind, _, change in parsed[len(document['resource_changes']):]: |
| + if kind == 'aws_autoscaling_group' and change['before'] is not None: |
| + drift_before.setdefault(address, []).append(change['before']) |
| entries = allow_entries(entries) |
| disposable = cleanup_entries(manifest, rows, groups) |
| existing = [(address, kind, name, change['before']) |
| @@ -545,6 +549,13 @@ def check(document, entries, manifest): |
| raise Refused(UNKNOWN % address) |
| if index < len(document['resource_changes']) and new < old: |
| raise Refused(DECREASE % address) |
| + if index < len(document['resource_changes']): |
| + for baseline in drift_before.get(address, []): |
| + applied = baseline.get(key) |
| + if type(applied) is not int or applied < 0: |
| + raise Refused(UNKNOWN % address) |
| + if new < applied: |
| + raise Refused(DECREASE % address) |
| # Stale exceptions do not silently carry into a different plan. |
| for entry in entries: |
| matches = [change for address, _, _, change in parsed if address == entry['address']] |
diff --git a/scripts/check_region_group_plan_test.py b/scripts/check_region_group_plan_test.py| index 453c75fe1..577c2c1f3 100644 |
| --- a/scripts/check_region_group_plan_test.py |
| +++ b/scripts/check_region_group_plan_test.py |
| @@ -328,6 +328,24 @@ class GateTests(unittest.TestCase): |
| 'aws_autoscaling_group', 'group', baseline, standby)] |
| self.gate(document, 0) |
| + def test_asg_planned_sizes_against_last_applied_drift(self): |
| + for attr in ['min_size', 'max_size', 'desired_capacity']: |
| + for applied, live, planned, expected in [(3, 1, 2, 1), (3, 1, 1, 1), |
| + (2, 1, 2, 0), (3, 2, 1, 1)]: |
| + with self.subTest(attr=attr, applied=applied, live=live, planned=planned): |
| + baseline = dict(min_size=1, max_size=3, desired_capacity=1) |
| + before = dict(baseline, **{attr: live}) |
| + after = dict(baseline, **{attr: planned}) |
| + document = plan(resource('aws_autoscaling_group.group', |
| + 'aws_autoscaling_group', 'group', before, after, |
| + actions=['no-op'] if live == planned else ['update'])) |
| + document['resource_drift'] = [resource('aws_autoscaling_group.group', |
| + 'aws_autoscaling_group', 'group', |
| + dict(baseline, **{attr: applied}), before)] |
| + result = self.gate(document, expected) |
| + if expected: |
| + self.assertIn('would decrease', result.stderr) |
| + |
| def test_asg_planned_decrease_from_refreshed_size(self): |
| for old, new, drifted in [(2, 1, False), (3, 2, True)]: |
| with self.subTest(drifted=drifted): |