route53: diff support (#64867)

* Refactoring.

* Add diff support.

* Add changelog.
pull/65544/head
Felix Fontein 5 years ago committed by GitHub
parent fb69d68821
commit c3d5371510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -472,6 +472,39 @@ def invoke_with_throttling_retries(function_ref, *argv, **kwargs):
retries += 1 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(): def main():
argument_spec = ec2_argument_spec() argument_spec = ec2_argument_spec()
argument_spec.update(dict( argument_spec.update(dict(
@ -615,11 +648,8 @@ def main():
rset = invoke_with_throttling_retries(next, sets_iter) rset = invoke_with_throttling_retries(next, sets_iter)
except StopIteration: except StopIteration:
break break
# Due to a bug in either AWS or Boto, "special" characters are returned as octals, preventing round # Need to save decoded name in rset, because of comparing rset.to_xml() == wanted_rset.to_xml() in next block
# tripping of things like * and @. decoded_name = decode_name(rset.name)
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
rset.name = decoded_name rset.name = decoded_name
if identifier_in is not None: if identifier_in is not None:
@ -630,26 +660,7 @@ def main():
# Sort records # Sort records
rset.resource_records = sorted(rset.resource_records) rset.resource_records = sorted(rset.resource_records)
found_record = True found_record = True
record['zone'] = zone_in record = to_dict(rset, zone_in, zone_id)
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)
if command_in == 'create' and rset.to_xml() == wanted_rset.to_xml(): if command_in == 'create' and rset.to_xml() == wanted_rset.to_xml():
module.exit_json(changed=False) module.exit_json(changed=False)
@ -700,7 +711,13 @@ def main():
except TimeoutError: except TimeoutError:
module.fail_json(msg='Timeout waiting for changes to replicate') 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__': if __name__ == '__main__':

Loading…
Cancel
Save