Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions pkg/providers/cloudflare/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,27 @@ func (d *dnsProvider) GetResource(ctx context.Context) (*schema.Resources, error
metadata = d.getDNSRecordMetadata(&record, &zone)
}

list.Append(&schema.Resource{
Public: true,
Provider: providerName,
DNSName: record.Name,
ID: d.id,
Service: d.name(),
Metadata: metadata,
})
// Skip CNAME records values to discard duplidate data
if record.Type == "CNAME" {
continue
}

// Create a single resource with both DNS name and IP
// The schema layer will handle keeping them together for DNS service
resource := &schema.Resource{
Public: true,
Provider: providerName,
DNSName: record.Name,
ID: d.id,
Service: d.name(),
Metadata: metadata,
}

if record.Type == "A" {
// Add IP information based on record type
// For A and AAAA records, include the IP in the same resource
if record.Type == "A" && record.Content != "" {
resource.PublicIPv4 = record.Content
} else {
} else if record.Type == "AAAA" && record.Content != "" {
resource.PublicIPv6 = record.Content
}
// For CNAME records, only DNS name is included

// Use the standard Append method which now has special handling for DNS service
list.Append(resource)
}
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,41 @@ func (r *Resources) appendResourceWithTypeAndMeta(resourceType validate.Resource

// appendResource appends a resource to the resources list
func (r *Resources) appendResource(resource *Resource) {
// Special handling for DNS providers: if resource has BOTH DNS name and IP, keep them together
hasDNS := resource.DNSName != ""
hasIP := resource.PublicIPv4 != "" || resource.PublicIPv6 != "" || resource.PrivateIpv4 != "" || resource.PrivateIpv6 != ""

if hasDNS && hasIP && resource.Service == "dns" {
// For DNS service records with both DNS and IP, append as-is without splitting
// Check if any value is new
anyNew := false
if hasDNS && !r.deduplicator.Contains(resource.DNSName) {
r.deduplicator.Add(resource.DNSName)
anyNew = true
}
if resource.PublicIPv4 != "" && !r.deduplicator.Contains(resource.PublicIPv4) {
r.deduplicator.Add(resource.PublicIPv4)
anyNew = true
}
if resource.PublicIPv6 != "" && !r.deduplicator.Contains(resource.PublicIPv6) {
r.deduplicator.Add(resource.PublicIPv6)
anyNew = true
}
if resource.PrivateIpv4 != "" && !r.deduplicator.Contains(resource.PrivateIpv4) {
r.deduplicator.Add(resource.PrivateIpv4)
anyNew = true
}
if resource.PrivateIpv6 != "" && !r.deduplicator.Contains(resource.PrivateIpv6) {
r.deduplicator.Add(resource.PrivateIpv6)
anyNew = true
}
if anyNew {
r.Items = append(r.Items, resource)
}
return
}

// Original behavior for all other cases: split into separate records
if resource.DNSName != "" && !r.deduplicator.Contains(resource.DNSName) {
resourceType := validator.Identify(resource.DNSName)
r.appendResourceWithTypeAndMeta(resourceType, resource.DNSName, resource.ID, resource.Provider, resource.Service, resource.Metadata)
Expand Down
Loading