diff --git a/powerdns_record.py b/powerdns_record.py index 27872dc..e4f97e6 100644 --- a/powerdns_record.py +++ b/powerdns_record.py @@ -216,7 +216,10 @@ def _get_request_data(self, changetype, server, zone, name, rtype, set_ptr=False record_content = list() if content: for record in content: - entry = dict(content=record, disabled=disabled) + if rtype == "CNAME": + entry = dict(content=self._make_canonical(record), disabled=disabled) + else: + entry = dict(content=record, disabled=disabled) if rtype in ['A', 'AAAA'] and set_ptr: entry['set-ptr'] = True @@ -310,8 +313,11 @@ def ensure(module, pdns_client): record = pdns_client.get_record(name=name, server=server, rtype=rtype, zone=zone_name) existing_content = [c.get('content') for c in record["records"]] + # Sanitize user-provided input for certain record types if content: + if rtype == 'CNAME': + content = "{}.".format(content) if rtype == 'AAAA': # Lowercase IPv6 addresses to match case returned by the API. # Necessary for later comparisons.