0
votes

I'm working on an Azure CLI script to automate the creation of a vnet in our cloud infrastructure. One of the parts in this script is linking a VNET to a Azure Private DNS. This should be easy, but apperently the difficulty is the fact that the VNET and the Private DNS are in a different resourcegroup.

This is my script;

   az network private-dns link vnet create --name MyLink \
     --registration-enabled true \
     --resource-group my-vnet-resourcegroup\
     --subscription 'My Subscription' \
     --tags Domain=MyDomain \
     --virtual-network my-own-vnet \
     --zone-name myzone.nu

Now when exuting i'm getting the following error;

Can not perform requested operation on nested resource. Parent resource 'myzone.nu' not found.

So I updated the script to look at the resourcegroup for the private DNS;

   az network private-dns link vnet create --name MyLink \
     --registration-enabled true \
     --resource-group my-privatedns-resourcegroup \
     --subscription 'My Subscription' \
     --tags Domain=MyDomain \
     --virtual-network my-own-vnet \
     --zone-name myzone.nu

This gives me the following error;

Deployment failed. Correlation ID: (SomeGuid). Virtual network resource not found for '/subscriptions//resourceGroups/my-privatedns-resourcegroup/providers/Microsoft.Network/virtualNetworks/my-own-vnet'

I'm quite stuck at the moment on how to fix this. Anybody else ran into this before? I'm open to suggestions!

1

1 Answers

2
votes

You could pass virtual network Id to the private DNS link vNet creation if the Virtual network is in another resource group which differs from your DNS zone resource group.

VnetID=$(az network vnet show -g vnet-rg -n my-vnet --query 'id' -o tsv)
az network private-dns link vnet create -n mylink -e true -g dns-rg -z myzone.nu -v $VnetID

enter image description here

or, you could use Azure Powershell.

$vnet = Get-AzVirtualNetwork -name my-own-vnet -ResourceGroupName my-vnet-resourcegroup

New-AzPrivateDnsVirtualNetworkLink -ZoneName private.contoso.com `
  -ResourceGroupName MyAzureResourceGroup -Name "mylink" `
  -VirtualNetworkId $vnet.id -EnableRegistration