diff --git a/octodns/provider/route53.py b/octodns/provider/route53.py index a8b47b8..c2567bb 100644 --- a/octodns/provider/route53.py +++ b/octodns/provider/route53.py @@ -380,6 +380,19 @@ class _Route53DynamicValue(_Route53Record): return '{}-{:03d}'.format(self.pool_name, self.index) def mod(self, action, existing_rrsets): + + if action == 'DELETE': + # When deleting records try and find the original rrset so that + # we're 100% sure to have the complete & accurate data (this mostly + # ensures we have the right health check id when there's multiple + # potential matches) + for existing in existing_rrsets: + if self.identifer == existing.get('SetIdentifier', None): + return { + 'Action': action, + 'ResourceRecordSet': existing, + } + return { 'Action': action, 'ResourceRecordSet': { @@ -442,8 +455,8 @@ class _Route53GeoRecord(_Route53Record): set_identifier = geo.code if action == 'DELETE': - # We deleting records try and find the original rrset so that we're - # 100% sure to have the complete & accurate data (this mostly + # When deleting records try and find the original rrset so that + # we're 100% sure to have the complete & accurate data (this mostly # ensures we have the right health check id when there's multiple # potential matches) for existing in existing_rrsets: diff --git a/tests/test_octodns_provider_route53.py b/tests/test_octodns_provider_route53.py index 4a4f90a..a5d00e2 100644 --- a/tests/test_octodns_provider_route53.py +++ b/tests/test_octodns_provider_route53.py @@ -12,7 +12,8 @@ from mock import patch from octodns.record import Create, Delete, Record, Update from octodns.provider.route53 import Route53Provider, _Route53GeoDefault, \ - _Route53GeoRecord, _Route53Record, _mod_keyer, _octal_replace + _Route53DynamicValue, _Route53GeoRecord, _Route53Record, _mod_keyer, \ + _octal_replace from octodns.zone import Zone from helpers import GeoProvider @@ -2054,6 +2055,46 @@ class TestRoute53Records(TestCase): e.__repr__() f.__repr__() + def test_dynamic_value_delete(self): + provider = DummyProvider() + geo = _Route53DynamicValue(provider, self.record_a, 'iad', '2.2.2.2', + 1, 0, False) + + rrset = { + 'HealthCheckId': 'x12346z', + 'Name': '_octodns-iad-value.unit.tests.', + 'ResourceRecords': [{ + 'Value': '2.2.2.2' + }], + 'SetIdentifier': 'iad-000', + 'TTL': 99, + 'Type': 'A', + 'Weight': 1, + } + + candidates = [ + # Empty, will test no SetIdentifier + {}, + { + 'SetIdentifier': 'not-a-match', + }, + rrset, + ] + + # Provide a matching rrset so that we'll just use it for the delete + # rathr than building up an almost identical one, note the way we'll + # know that we got the one we passed in is that it'll have a + # HealthCheckId and one that was created wouldn't since DummyProvider + # stubs out the lookup for them + mod = geo.mod('DELETE', candidates) + self.assertEquals('x12346z', mod['ResourceRecordSet']['HealthCheckId']) + + # If we don't provide the candidate rrsets we get back exactly what we + # put in minus the healthcheck + rrset['HealthCheckId'] = None + mod = geo.mod('DELETE', []) + self.assertEquals(rrset, mod['ResourceRecordSet']) + def test_geo_delete(self): provider = DummyProvider() geo = _Route53GeoRecord(provider, self.record_a, 'NA-US',