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
31 changes: 31 additions & 0 deletions internal/driver/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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...)
}
29 changes: 28 additions & 1 deletion internal/driver/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand All @@ -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) {
Expand Down
Loading