Skip to content

Commit

Permalink
Fix route53 idempotency issues (ansible-collections#525)
Browse files Browse the repository at this point in the history
* Fix name comparison: AWS uses octal encoding for characters like '@' and '*'.
* Fix CAA record ordering.
* Add changelog fragment.
* Add wildcard record test.

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@351ba4a
  • Loading branch information
felixfontein authored and goneri committed Sep 21, 2022
1 parent bb2dee7 commit 1bec550
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugins/modules/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ def get_record(route53, zone_id, record_name, record_type, record_identifier):
record_sets_results = _list_record_sets(route53, HostedZoneId=zone_id)

for record_set in record_sets_results:
record_set['Name'] = record_set['Name'].encode().decode('unicode_escape')
# If the record name and type is not equal, move to the next record
if (record_name, record_type) != (record_set['Name'], record_set['Type']):
if (record_name.lower(), record_type) != (record_set['Name'].lower(), record_set['Type']):
continue

if record_identifier and record_identifier != record_set.get("SetIdentifier"):
Expand Down Expand Up @@ -573,6 +574,8 @@ def main():
# On CAA records order doesn't matter
if type_in == 'CAA':
resource_record_set['ResourceRecords'] = sorted(resource_record_set['ResourceRecords'], key=itemgetter('Value'))
if aws_record:
aws_record['ResourceRecords'] = sorted(aws_record['ResourceRecords'], key=itemgetter('Value'))

if command_in == 'create' and aws_record == resource_record_set:
module.exit_json(changed=False)
Expand Down
57 changes: 57 additions & 0 deletions tests/integration/targets/route53/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,63 @@
- caa is not failed
- caa is not changed

- name: Create an A record for a wildcard prefix
route53:
state: present
zone: '{{ zone_one }}'
record: '*.wildcard_test.{{ zone_one }}'
type: A
value:
- 192.0.2.1
register: wc_a_record
- assert:
that:
- wc_a_record is not failed
- wc_a_record is changed

- name: Create an A record for a wildcard prefix (idempotency)
route53:
state: present
zone: '{{ zone_one }}'
record: '*.wildcard_test.{{ zone_one }}'
type: A
value:
- 192.0.2.1
register: wc_a_record
- assert:
that:
- wc_a_record is not failed
- wc_a_record is not changed

- name: Create an A record for a wildcard prefix (change)
route53:
state: present
zone: '{{ zone_one }}'
record: '*.wildcard_test.{{ zone_one }}'
type: A
value:
- 192.0.2.2
overwrite: true
register: wc_a_record
- assert:
that:
- wc_a_record is not failed
- wc_a_record is changed

- name: Delete an A record for a wildcard prefix
route53:
state: absent
zone: '{{ zone_one }}'
record: '*.wildcard_test.{{ zone_one }}'
type: A
value:
- 192.0.2.2
register: wc_a_record
- assert:
that:
- wc_a_record is not failed
- wc_a_record is changed

# Tests on zone two (private zone)
- name: Create A record using zone fqdn
route53:
Expand Down

0 comments on commit 1bec550

Please sign in to comment.