Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix state=get on route53 module (Issue #423) #424

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/406-route53-state-get.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- route53 - fix when using `state=get` on private DNS zones and add tests to cover this scenario (https://github.com/ansible-collections/community.aws/pull/424).
tremble marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 12 additions & 1 deletion plugins/modules/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,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']),
Expand Down Expand Up @@ -564,7 +575,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)

Expand Down
14 changes: 14 additions & 0 deletions tests/integration/targets/route53/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@
- qdn is not failed
- qdn is changed

- name: Get A record using 'get' method of route53 module
route53:
state: get
zone: "{{ zone_one }}"
record: "qdn_test.{{ zone_one }}"
type: A
register: get_result
- assert:
that:
- get_result.nameservers|length > 0
- get_result.set.Name == "qdn_test.{{ zone_one }}"
- get_result.set.ResourceRecords[0].Value == "1.2.3.4"
- get_result.set.Type == "A"

- name: Create same A record using zone non-qualified domain
route53:
state: present
Expand Down