Repository: ansible-collections/community.aws

Issue:
route53 idempotency issues
##### SUMMARY
Since #405, route53 has several idempotency issues when running with `-C --diff`:
1. it tries to change CAA entries where the values are in a different order;
2. it tries to re-add wildcard records that already exist.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
route53

##### ANSIBLE VERSION
```paste below
devel
```



Discussion:
Files identified in the description:
* [`plugins/modules/route53.py`](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/plugins/modules/route53.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @jillr @jimbydamonk @s-hertel @tremble @wimnat
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
1. is a regression for ansible/ansible#46049.
2. is caused by removing the escaped character handling (see for example https://github.com/ansible/ansible/pull/60508).

Resolving patch:
diff --git a/plugins/modules/route53.py b/plugins/modules/route53.py
--- a/plugins/modules/route53.py
+++ b/plugins/modules/route53.py
@@ -384,8 +384,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"):
@@ -561,6 +562,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)


Test patch:
diff --git a/tests/integration/targets/route53/tasks/main.yml b/tests/integration/targets/route53/tasks/main.yml
--- a/tests/integration/targets/route53/tasks/main.yml
+++ b/tests/integration/targets/route53/tasks/main.yml
@@ -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: