2022-05-24 04:04:42 -04:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
|
|
|
|
)
|
|
|
|
|
|
|
|
// getVirtualNetwork return the first virtual network found in the resource group.
|
|
|
|
func (m *Metadata) getVirtualNetwork(ctx context.Context, resourceGroup string) (*armnetwork.VirtualNetwork, error) {
|
2022-07-27 16:02:33 -04:00
|
|
|
pager := m.virtualNetworksAPI.NewListPager(resourceGroup, nil)
|
|
|
|
for pager.More() {
|
|
|
|
page, err := pager.NextPage(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("retrieving virtual networks: %w", err)
|
|
|
|
}
|
|
|
|
for _, network := range page.Value {
|
2022-05-24 04:04:42 -04:00
|
|
|
if network != nil {
|
|
|
|
return network, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("no virtual network found in resource group %s", resourceGroup)
|
|
|
|
}
|