| index bfff772b9..577c2c1f3 100644 |
| --- a/scripts/check_region_group_plan_test.py |
| +++ b/scripts/check_region_group_plan_test.py |
| @@ -319,6 +319,68 @@ 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_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): |
| + 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) |