route53: diff support (#64867)

* Refactoring.

* Add diff support.

* Add changelog.
This commit is contained in:
Felix Fontein 2019-12-05 06:22:11 +01:00 committed by GitHub
parent fb69d68821
commit c3d5371510
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 26 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "route53 - the module now has diff support."

View file

@ -472,6 +472,39 @@ def invoke_with_throttling_retries(function_ref, *argv, **kwargs):
retries += 1
def decode_name(name):
# Due to a bug in either AWS or Boto, "special" characters are returned as octals, preventing round
# tripping of things like * and @.
decoded_name = name.replace(r'\052', '*')
decoded_name = decoded_name.replace(r'\100', '@')
return decoded_name
def to_dict(rset, zone_in, zone_id):
record = dict()
record['zone'] = zone_in
record['type'] = rset.type
record['record'] = decode_name(rset.name)
record['ttl'] = str(rset.ttl)
record['identifier'] = rset.identifier
record['weight'] = rset.weight
record['region'] = rset.region
record['failover'] = rset.failover
record['health_check'] = rset.health_check
record['hosted_zone_id'] = zone_id
if rset.alias_dns_name:
record['alias'] = True
record['value'] = rset.alias_dns_name
record['values'] = [rset.alias_dns_name]
record['alias_hosted_zone_id'] = rset.alias_hosted_zone_id
record['alias_evaluate_target_health'] = rset.alias_evaluate_target_health
else:
record['alias'] = False
record['value'] = ','.join(sorted(rset.resource_records))
record['values'] = sorted(rset.resource_records)
return record
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
@ -615,11 +648,8 @@ def main():
rset = invoke_with_throttling_retries(next, sets_iter)
except StopIteration:
break
# Due to a bug in either AWS or Boto, "special" characters are returned as octals, preventing round
# tripping of things like * and @.
decoded_name = rset.name.replace(r'\052', '*')
decoded_name = decoded_name.replace(r'\100', '@')
# Need to save this changes in rset, because of comparing rset.to_xml() == wanted_rset.to_xml() in next block
# Need to save decoded name in rset, because of comparing rset.to_xml() == wanted_rset.to_xml() in next block
decoded_name = decode_name(rset.name)
rset.name = decoded_name
if identifier_in is not None:
@ -630,26 +660,7 @@ def main():
# Sort records
rset.resource_records = sorted(rset.resource_records)
found_record = True
record['zone'] = zone_in
record['type'] = rset.type
record['record'] = decoded_name
record['ttl'] = rset.ttl
record['identifier'] = rset.identifier
record['weight'] = rset.weight
record['region'] = rset.region
record['failover'] = rset.failover
record['health_check'] = rset.health_check
record['hosted_zone_id'] = zone_id
if rset.alias_dns_name:
record['alias'] = True
record['value'] = rset.alias_dns_name
record['values'] = [rset.alias_dns_name]
record['alias_hosted_zone_id'] = rset.alias_hosted_zone_id
record['alias_evaluate_target_health'] = rset.alias_evaluate_target_health
else:
record['alias'] = False
record['value'] = ','.join(sorted(rset.resource_records))
record['values'] = sorted(rset.resource_records)
record = to_dict(rset, zone_in, zone_id)
if command_in == 'create' and rset.to_xml() == wanted_rset.to_xml():
module.exit_json(changed=False)
@ -700,7 +711,13 @@ def main():
except TimeoutError:
module.fail_json(msg='Timeout waiting for changes to replicate')
module.exit_json(changed=True)
module.exit_json(
changed=True,
diff=dict(
before=record,
after=to_dict(wanted_rset, zone_in, zone_id) if command != 'delete' else {},
),
)
if __name__ == '__main__':