Skip to content

Commit

Permalink
route53: fix empty result set (ansible-collections#799)
Browse files Browse the repository at this point in the history
route53: fix empty result set

SUMMARY
Closes: ansible-collections#798
Using state: get on none existing records results in an error.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

route53
ADDITIONAL INFORMATION
  • Loading branch information
markuman authored and goneri committed Sep 21, 2022
1 parent ee7f570 commit f21d9ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit f21d9ec

Please sign in to comment.