carlos / platform Public

region group plan gate: judge planned sizes, not drift

Standby can lower live minimum and desired capacity before a plan restores them. Compare planned sizes against refreshed live values so the drift decrease does not refuse that increase. Keep all other drift checks, including ASG deletion and unknown values.
claude agent, operated by paul@keymail.dev b8b3d1a5c1dd992f4f20ed15817ad7e820f9c606 parent 1cc9907
2 files changed, +46 −2
  • scripts/check-region-group-plan.py +2 −2
  • scripts/check_region_group_plan_test.py +44 −0

CI cancelled — superseded by a newer push — run details

diff --git a/scripts/check-region-group-plan.py b/scripts/check-region-group-plan.py
index a4ee8b437..488bb23d0 100755
--- a/scripts/check-region-group-plan.py
+++ b/scripts/check-region-group-plan.py
@@ -491,7 +491,7 @@ def check(document, entries, manifest):
for row, (address, kind, name, change) in zip(rows, parsed)
if row['mode'] == 'managed' and change['before'] is not None and change['after'] is not None]
identities = fixed_identities(existing + planned, groups)
- for row, (address, kind, name, change) in zip(rows, parsed):
+ for index, (row, (address, kind, name, change)) in enumerate(zip(rows, parsed)):
if row['mode'] == 'data':
continue
before, after, actions = change['before'], change['after'], change['actions']
@@ -543,7 +543,7 @@ def check(document, entries, manifest):
old, new = before.get(key), after.get(key)
if (type(old) is not int or type(new) is not int or old < 0 or new < 0):
raise Refused(UNKNOWN % address)
- if new < old:
+ if index < len(document['resource_changes']) and new < old:
raise Refused(DECREASE % address)
# Stale exceptions do not silently carry into a different plan.
for entry in entries:
diff --git a/scripts/check_region_group_plan_test.py b/scripts/check_region_group_plan_test.py
index bfff772b9..453c75fe1 100644
--- a/scripts/check_region_group_plan_test.py
+++ b/scripts/check_region_group_plan_test.py
@@ -319,6 +319,50 @@ class GateTests(unittest.TestCase):
self.gate(plan(resource('aws_autoscaling_group.group', 'aws_autoscaling_group',
'group', baseline, dict(min_size=3, max_size=3, desired_capacity=3))), 0)
+ def test_asg_planned_increase_after_standby_drift(self):
+ baseline = dict(min_size=2, max_size=2, desired_capacity=2)
+ standby = dict(baseline, min_size=1, desired_capacity=1)
+ document = plan(resource('aws_autoscaling_group.group', 'aws_autoscaling_group',
+ 'group', standby, baseline))
+ document['resource_drift'] = [resource('aws_autoscaling_group.group',
+ 'aws_autoscaling_group', 'group', baseline, standby)]
+ self.gate(document, 0)
+
+ 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):
+ before = dict(min_size=old, max_size=3, desired_capacity=old)
+ after = dict(min_size=new, max_size=3, desired_capacity=new)
+ document = plan(resource('aws_autoscaling_group.group',
+ 'aws_autoscaling_group', 'group', before, after))
+ if drifted:
+ document['resource_drift'] = [resource('aws_autoscaling_group.group',
+ 'aws_autoscaling_group', 'group', after, before)]
+ self.assertIn('would decrease', self.gate(document, 1).stderr)
+
+ def test_asg_drift_keeps_delete_and_shape_refusals(self):
+ baseline = dict(min_size=2, max_size=2, desired_capacity=2)
+ for mutation in ['delete', 'replace', 'unknown', 'missing', 'boolean', 'negative']:
+ with self.subTest(mutation=mutation):
+ document = plan(resource('aws_autoscaling_group.group',
+ 'aws_autoscaling_group', 'group', baseline, baseline, actions=['no-op']))
+ drift = resource('aws_autoscaling_group.group', 'aws_autoscaling_group',
+ 'group', baseline, dict(baseline))
+ change = drift['change']
+ if mutation == 'delete':
+ change.update(actions=['delete'], after=None)
+ elif mutation == 'replace':
+ change['actions'] = ['delete', 'create']
+ elif mutation == 'unknown':
+ change['after_unknown'] = {'min_size': True}
+ elif mutation == 'missing':
+ del change['after']['min_size']
+ else:
+ change['after']['min_size'] = True if mutation == 'boolean' else -1
+ document['resource_drift'] = [drift]
+ message = 'would decrease' if mutation in ['delete', 'replace'] else 'cannot safely read'
+ self.assertIn(message, self.gate(document, 1).stderr)
+
def test_fixed_eip_reassociation_and_ingress_protection(self):
self.gate(plan(resource('aws_eip.host', 'aws_eip', 'host',
{'instance': 'i-old'}, {'instance': 'i-new'})), 1)