Google Cloud DNS, python, and spf records

Problem:

I’ve been using the python Google cloudsDNS api to create spf records. The problem was that the TXT record was splitting the value on spaces, which breaks everything. Super fun stuff. Anyways, I spent way to long figuring out what the heck was going on.

Solution:

Obviously (read with sarcasm), you need to wrap the value in an extra quote. I guess cloudDNS likes TXT records to be lists of string. Heres a code snippet for the off chance someone reads this while tackling the same problem.

zone = self.get_zone(ZONE_NAME)
changes = zone.changes()

# double quotes are here
new_record = zone.resource_record_set(DOMAIN_NAME, "TXT", 300, ['"v=spf1 -all"'])
changes.add_record_set(new_record)
changes.create()

also, in case you’re like me and hate the fact that the “Documentation” link here really leads to useless tutorials, here’s the actual api docs.