Consider the following scenario:
- One resource-group called
rg-foo
which was created in the locationswitzerlandnorth
- One virtual network called
vnet-switzerland-north
holding one subnet calleddefault
also in the locationswitzerlandnorth
- The mentioned vnet is part of another resource-group called
rg-vnets
which is atwesteurope
Now I'd like to create a NIC and attach it to subnet default
. So here is what I did:
az network nic create --name nicfoo --subnet default --vnet-name vnet-switzerland-north --resource-group rg-foo
Which however results in...
BadRequestError: Resource /subscriptions/subscription-guid/resourceGroups/rg-foo/providers/Microsoft. Network/virtualNetworks/vnet-switzerland-north/subnets/default referenced by resource /subscriptions/subscription-guid/resourceGroups/rg-foo/providers/Microsoft.Network/networkInterfaces/nicfoo was not found. Please make sure that the referenced resource exists, and that both resources are in the same region.
I just can't make any sense out of this error message. Of course the vnet and subnet exists, double and triple checked also their location. Even if I add the --location
parameter and explicitly state that I want the nic to be in the same region the same error occurs.
Also providing the id like this doesn't make any change.
subnetid=$(az network vnet subnet show --vnet-name vnet-switzerland-north --name default --resource-group rg-vnets --output tsv --query [id])
az network nic create --name nicfoo --subnet $subnetid
What am I doing wrong here?
Edit
- Updating to the latest Azure CLI version (2.13.0) didn't make a change
- I am able to create the nic via azure portal without any issues
If I create another test-vnet (@switzerlandnorth
) and put it into rg-foo (@switzerlandnorth
) then I am able to create a nic in that rg with the beforementioned parameters. It seems that the Azure CLI doesn't like the fact that rg-vnets
is in westeurope
.
Edit
What's also interesting is that it works with Azure PowerShell.
$vnet = Get-AzVirtualNetwork -Name vnet-switzerland-north
$subnet = Get-AzVirtualNetworkSubnetConfig -Name default -VirtualNetwork $vnet
$nic = New-AzNetworkInterface -Name nicfoo -ResourceGroupName rg-foo -Subnet $subnet -Location switzerlandnorth