Skip to content

Commit

Permalink
Fix zfinding zone without resource group
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry committed Aug 12, 2022
1 parent b88671d commit 3ef22bb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/services/dns/dns_zone_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func dataSourceDnsZoneRead(d *pluginsdk.ResourceData, meta interface{}) error {
}

zone = result
id.ResourceGroupName = *resourceGroupName
}

if zone == nil {
Expand Down Expand Up @@ -125,23 +126,23 @@ func findZone(ctx context.Context, client *zones.ZonesClient, subscriptionId, na
return nil, nil, fmt.Errorf("listing DNS Zones: %+v", err)
}

var found *zones.Zone
var found zones.Zone
for _, zone := range zonesIterator.Items {
if zone.Name != nil && *zone.Name == name {
if found != nil {
if found.Id != nil {
return nil, nil, fmt.Errorf("found multiple DNS zones with name %q, please specify the resource group", name)
}
found = &zone
found = zone
}
}

if found == nil || found.Id == nil {
if found.Id == nil {
return nil, nil, fmt.Errorf("could not find DNS zone with name: %q", name)
}

id, err := zones.ParseDnsZoneIDInsensitively(*found.Id)
if err != nil {
return nil, nil, fmt.Errorf("parsing %q as a DNS Zone ID: %+v", *found.Id, err)
}
return found, &id.ResourceGroupName, nil
return &found, &id.ResourceGroupName, nil
}

0 comments on commit 3ef22bb

Please sign in to comment.