diff --git a/engine/resources/cloudflare_dns.go b/engine/resources/cloudflare_dns.go index 7792e46e..d8d09a33 100644 --- a/engine/resources/cloudflare_dns.go +++ b/engine/resources/cloudflare_dns.go @@ -161,8 +161,10 @@ func (obj *CloudflareDNSRes) Validate() error { return fmt.Errorf("priority is required for MX records") } - if obj.MetaParams().Poll == 0 || obj.MetaParams().Poll < 1 { // CF accepts ~4req/s so this is good enough - return fmt.Errorf("cloudflare:dns requires polling, set Meta:poll param (e.g., 60 seconds), min. 1s") + // cloudflare accepts ~4req/s so this is safe enough even when managing lots + // of records + if obj.MetaParams().Poll == 0 || obj.MetaParams().Poll < 60 { + return fmt.Errorf("cloudflare:dns requires polling, set Meta:poll param (e.g., 300s), min. 60s") } return nil @@ -216,21 +218,6 @@ func (obj *CloudflareDNSRes) Watch(context.Context) error { // if necessary. If apply is false, it only checks if changes are needed. If // Purge is enabled, it will first delete any unmanaged records in the zone. func (obj *CloudflareDNSRes) CheckApply(ctx context.Context, apply bool) (bool, error) { - zone, err := obj.client.Zones.List(ctx, zones.ZoneListParams{ - Name: cloudflare.F(obj.Zone), - }) - if err != nil { - return false, err - } - - if len(zone.Result) == 0 { - return false, fmt.Errorf("there's no zone registered with name %s", obj.Zone) - } - - if len(zone.Result) > 1 { - return false, fmt.Errorf("there's more than one zone with name %s", obj.Zone) - } - // We start by checking the need for purging if obj.Purge { checkOK, err := obj.purgeCheckApply(ctx, apply) @@ -374,10 +361,18 @@ func (obj *CloudflareDNSRes) Cmp(r engine.Res) error { return fmt.Errorf("content param differs") } - if obj.Priority != res.Priority { + if (obj.Priority == nil) != (res.Priority == nil) { return fmt.Errorf("the priority param differs") } + if obj.Priority != nil && *obj.Priority != *obj.Priority { + return fmt.Errorf("the priority param differs") + } + + if obj.Data != res.Data { + return fmt.Errorf("the data param differs") + } + return nil } @@ -469,10 +464,10 @@ func (obj *CloudflareDNSRes) buildRecordParam() (any, error) { case "NS": param := dns.NSRecordParam{ - Name: cloudflare.F(obj.RecordName), - Type: cloudflare.F(dns.NSRecordTypeNS), - Content: cloudflare.F(obj.Content), - TTL: cloudflare.F(ttl), + Name: cloudflare.F(obj.RecordName), + Type: cloudflare.F(dns.NSRecordTypeNS), + Data: cloudflare.F(obj.Data), + TTL: cloudflare.F(ttl), } if obj.Proxied != nil { param.Proxied = cloudflare.F(*obj.Proxied) @@ -659,6 +654,10 @@ func (obj *CloudflareDNSRes) purgeCheckApply(ctx context.Context, apply bool) (b if cfRes.Zone == obj.Zone { recordKey := fmt.Sprintf("%s:%s:%s", cfRes.RecordName, cfRes.Type, cfRes.Content) + if cfRes.Priority != nil { + // corner case for MX records which require priority set + recordKey = fmt.Sprintf("%s:%d", recordKey, *cfRes.Priority) + } excludes[recordKey] = true } }