---
version: '3'

tasks:
  cloudflare:dns:
    summary: |
      This task sets up CNAME Record pointing to the given Value, in Cloudflare DNS. This is primarily used in
      conjunciton with Heroku tasks to setup custom domains. These variables are needed:
        CONFIGURE_CLOUDFLARE_DNS: Set to `true` to configure Cloudflare DNS
        CLOUDFLARE_DNS_ZONE: Name of the DNS Zone where the record should be added to
        CLOUDFLARE_API_TOKEN: API Token to authenticate to Cloudflare
        CLOUDFLARE_RECORD_NAME: The name of the record
        CLOUDFLARE_RECORD_VALUE: Target for the CNAME record
    cmds:
      - |
        {{if eq .CONFIGURE_CLOUDFLARE_DNS "true")}}curl -X POST "https://api.cloudflare.com/client/v4/zones/{{.CLOUDFLARE_DNS_ZONE}}/dns_records/" \
        -H "Authorization: Bearer {{.CLOUDFLARE_API_TOKEN}}" \
        -H "Content-Type: application/json" \
        --data '{"type":"CNAME","name":"{{.CLOUDFLARE_RECORD_NAME}}","content":"{{.CLOUDFLARE_RECORD_VALUE}}","proxied":true,"ttl":3600}'{{end}}
