0

Consider the following scenario:

  • One resource-group called rg-foo which was created in the location switzerlandnorth
  • One virtual network called vnet-switzerland-north holding one subnet called default also in the location switzerlandnorth
  • The mentioned vnet is part of another resource-group called rg-vnets which is at westeurope

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
Matthias Güntert
  • 2,438
  • 12
  • 39
  • 59
  • Have you set the correct subscription in the CLI using az account set --subscription if you have more than one sub it could be looking at the wrong one – Sam Cogan Oct 15 '20 at 07:59
  • Thanks for replying. There is only one subscription which is correctly set (checked with `az account list` => `IsDefault=True`). The issue seems related to the location of `rg-vnets`, please see my updated question. – Matthias Güntert Oct 15 '20 at 09:05

1 Answers1

0

You can't create a network card in a different region to the vNet/Subnet it is going to be attached to, they need to be in the same region. Because you are not specifying the location in your Azure CLI command it is taking the location of the resource group, west europe, causing this issue.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
  • Hm, but then the following should work right? `az network nic create --name nicfoo --subnet default --vnet-name vnet-switzerland-north --location switzerlandnorth --resource-group rg-foo` but it also results in a `BadRequestError`. Both `rg-foo` and `vnet-switzerland-north` are @`switzerlandnorth`. The only special thing is that the vnet is held by a resource-group (`rg-vnets`) which is in west-europe – Matthias Güntert Oct 15 '20 at 17:40
  • Also when using Azure PowerShell it works.. see my updated question – Matthias Güntert Oct 15 '20 at 18:02
  • The command your running should work, I would look at raising a bug in the Azure CLI repo – Sam Cogan Oct 20 '20 at 08:59