From dee8d6ee22d541d205966f0a6f675fb08aa92225 Mon Sep 17 00:00:00 2001 From: Jon Langevin Date: Sun, 24 May 2026 00:59:44 -0400 Subject: [PATCH] feat: add azure dns authority outputs --- internal/driver/dns.go | 31 +++++++++++++++++++++++++++++++ internal/driver/dns_test.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/internal/driver/dns.go b/internal/driver/dns.go index 8bf1b91..ae06d1b 100644 --- a/internal/driver/dns.go +++ b/internal/driver/dns.go @@ -123,11 +123,27 @@ func (d *DNSDriver) Scale(_ context.Context, _ interfaces.ResourceRef, _ int) (* func dnsToOutput(name string, z armdns.Zone) *interfaces.ResourceOutput { outputs := map[string]any{} + if z.Name != nil { + outputs["domain"] = *z.Name + outputs["zone_name"] = *z.Name + } if z.Properties != nil { if z.Properties.NumberOfRecordSets != nil { outputs["record_sets"] = *z.Properties.NumberOfRecordSets + outputs["record_count"] = *z.Properties.NumberOfRecordSets + } + if z.Properties.ZoneType != nil { + outputs["zone_type"] = string(*z.Properties.ZoneType) + } + if len(z.Properties.NameServers) > 0 { + outputs["name_servers"] = azureNameServers(z.Properties.NameServers) } } + outputs["authority"] = map[string]any{ + "role": "target_authoritative_dns", + "dns_host": "Azure DNS", + "name_servers": azureOutputNameServers(outputs), + } status := "active" if z.ID == nil { status = "unknown" @@ -140,3 +156,18 @@ func dnsToOutput(name string, z armdns.Zone) *interfaces.ResourceOutput { Status: status, } } + +func azureNameServers(values []*string) []string { + out := make([]string, 0, len(values)) + for _, value := range values { + if value != nil { + out = append(out, *value) + } + } + return out +} + +func azureOutputNameServers(outputs map[string]any) []string { + values, _ := outputs["name_servers"].([]string) + return append([]string(nil), values...) +} diff --git a/internal/driver/dns_test.go b/internal/driver/dns_test.go index e7c3301..04bfb01 100644 --- a/internal/driver/dns_test.go +++ b/internal/driver/dns_test.go @@ -58,10 +58,17 @@ func TestDNSDriver_Create(t *testing.T) { } func TestDNSDriver_Read(t *testing.T) { + zoneType := armdns.ZoneTypePublic client := &mockDNSClient{ getFn: func(_ context.Context, _, zoneName string) (armdns.Zone, error) { return armdns.Zone{ - ID: str("/subscriptions/sub/rg/" + zoneName), + ID: str("/subscriptions/sub/rg/" + zoneName), + Name: str(zoneName), + Properties: &armdns.ZoneProperties{ + NameServers: []*string{str("ns1-01.azure-dns.com."), str("ns2-01.azure-dns.net.")}, + NumberOfRecordSets: ptrOf(int64(3)), + ZoneType: &zoneType, + }, }, nil }, } @@ -74,6 +81,26 @@ func TestDNSDriver_Read(t *testing.T) { if out.Status != "active" { t.Errorf("status = %q, want active", out.Status) } + if out.Outputs["domain"] != "example.com" { + t.Fatalf("domain = %v, want example.com", out.Outputs["domain"]) + } + if out.Outputs["record_count"] != int64(3) { + t.Fatalf("record_count = %v, want 3", out.Outputs["record_count"]) + } + if out.Outputs["zone_type"] != "Public" { + t.Fatalf("zone_type = %v, want Public", out.Outputs["zone_type"]) + } + authority, ok := out.Outputs["authority"].(map[string]any) + if !ok { + t.Fatalf("authority = %T, want map[string]any", out.Outputs["authority"]) + } + if got := authority["dns_host"]; got != "Azure DNS" { + t.Fatalf("authority.dns_host = %v, want Azure DNS", got) + } + nameServers, ok := authority["name_servers"].([]string) + if !ok || len(nameServers) != 2 || nameServers[0] != "ns1-01.azure-dns.com." { + t.Fatalf("authority.name_servers = %#v, want Azure DNS nameservers", authority["name_servers"]) + } } func TestDNSDriver_Create_Error(t *testing.T) {