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

route53: fix empty result set #799

Merged
merged 3 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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/798-fix-route53-empty-result.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- route53 - return empty result for nonexistent records (https://github.com/ansible-collections/community.aws/pull/799).
5 changes: 5 additions & 0 deletions plugins/modules/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ def main():
ns = get_hosted_zone_nameservers(route53, zone_id)

formatted_aws = format_record(aws_record, zone_in, zone_id)

if formatted_aws is None:
# record does not exist
module.exit_json(changed=False, set=[], nameservers=ns, resource_record_sets=[])

rr_sets = [camel_dict_to_snake_dict(aws_record)]
module.exit_json(changed=False, set=formatted_aws, nameservers=ns, resource_record_sets=rr_sets)

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 @@ -417,6 +417,20 @@
- get_result.set.ResourceRecords[0].Value == "192.0.2.1"
- get_result.set.Type == "A"

- name: Get a record that does not exist
route53:
state: get
zone: "{{ zone_two }}"
record: "notfound.{{ zone_two }}"
type: A
private_zone: true
register: get_result
- assert:
that:
- get_result.nameservers|length > 0
- get_result.set|length == 0
- get_result.resource_record_sets|length == 0

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