From da184fcd8f9bf5b15be81e46f9343712b5655641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Magalh=C3=A3es?= <4622652+pjrm@users.noreply.github.com> Date: Thu, 11 Mar 2021 13:15:18 +0000 Subject: [PATCH] Fix state=get on route53 module (Issue #423) (#424) * Fix state=get on route53 module This bug was introduced when refactoring from boto to boto3 library. This happens because the method "get_hosted_zone" only returns the DelegationSet when the DNS zone is external. Therefore this breaks when trying to get internal records. The solution is to search for getting DNS records of type ''NS'' with the same name as the hosted zone. * Update changelogs/fragments/406-route53-state-get.yml Co-authored-by: Mark Chappell --- route53.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/route53.py b/route53.py index 43b17a44f5b..84a8dc997fb 100644 --- a/route53.py +++ b/route53.py @@ -424,6 +424,17 @@ def get_zone_id_by_name(route53, module, zone_name, want_private, want_vpc_id): return None +def get_hosted_zone_nameservers(route53, zone_id): + hosted_zone_name = route53.get_hosted_zone(aws_retry=True, Id=zone_id)['HostedZone']['Name'] + resource_records_sets = _list_record_sets(route53, HostedZoneId=zone_id) + + nameservers_records = list( + filter(lambda record: record['Name'] == hosted_zone_name and record['Type'] == 'NS', resource_records_sets) + )[0]['ResourceRecords'] + + return [ns_record['Value'] for ns_record in nameservers_records] + + def main(): argument_spec = dict( state=dict(type='str', required=True, choices=['absent', 'create', 'delete', 'get', 'present'], aliases=['command']), @@ -565,7 +576,7 @@ def main(): ns = aws_record.get('values', []) else: # Retrieve name servers associated to the zone. - ns = route53.get_hosted_zone(aws_retry=True, Id=zone_id)['DelegationSet']['NameServers'] + ns = get_hosted_zone_nameservers(route53, zone_id) module.exit_json(changed=False, set=aws_record, nameservers=ns)