Created
July 18, 2024 21:55
-
-
Save jph00/82582442cd5fedef9db0133c789e640b to your computer and use it in GitHub Desktop.
Add a cloudflare DNS record (A or CNAME)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/cloudflare/cloudflare-python/blob/main/api.md | |
from fastcore.script import * | |
from cloudflare import Cloudflare | |
@call_parse | |
def add_dns_record( | |
record_type: str, # Type of DNS record (CNAME or A) | |
target: str, # Target IP address or domain name | |
record: str, # Record name (without the zone) | |
zone: str, # Zone name | |
proxied: bool_arg=True # Use CF proxy? | |
): | |
cf = Cloudflare() | |
zones = cf.zones.list(name=zone) | |
if not zones: raise ValueError(f"Zone '{zone}' not found") | |
zid = zones.result[0].id | |
cf.dns.records.create(zone_id=zid, type=record_type.upper(), name=f"{record}.{zone}", content=target, proxied=proxied) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment