Azure / azure-cli

Azure Command-Line Interface
MIT License
3.92k stars 2.9k forks source link

az network nic create expects NIC to be stored in the same Resource Group as VNET #2795

Closed ghost closed 7 years ago

ghost commented 7 years ago

Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: apt-get CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: azure-cli (2.0.2)

acr (2.0.0) acs (2.0.2) appservice (0.1.2) batch (2.0.0) cloud (2.0.0) component (2.0.0) configure (2.0.2) container (0.1.2) core (2.0.2) documentdb (0.1.2) feedback (2.0.0) find (0.0.1b1) iot (0.1.2) keyvault (2.0.0) lab (0.0.1) monitor (0.0.1) network (2.0.2) nspkg (2.0.0) profile (2.0.2) redis (0.1.1b3) resource (2.0.2) role (2.0.1) sql (2.0.0) storage (2.0.2) vm (2.0.2)

Python (Linux) 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2]

OS Version: What OS and version are you using?
Answer here: Linux Debian 9

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: bash


Description

to reproduce: az group create -n networkingGroup -l "westeurope" az network vnet create --resource-group networkingGroup --name localnetwork --address-prefix 10.0.0.0/8 \ --subnet-name default --subnet-prefix 10.0.0.0/29

az group create -n myMVGroup -l "westeurope" az network public-ip create --resource-group myVMGroup --name myvm-pip az network nsg create --resource-group myVMGroup --name myvm-nsg

all above works like a charm, however while trying to create NIC:

az --verbose --debug network nic create \ --resource-group myVMGroup \ --name myvm-nic \ --vnet-name localnetwork \ --subnet default \ --network-security-group myvm-nsg \ --public-ip-address myvm-pip

Resource /subscriptions/xxxxx-xxxx-xxxx-xxxxx-xxxxxxx/resourceGroups/MANAGEMENT/providers/Microsoft.Network/virtualNetworks/LOCALNETWORK referenced by resource /subscriptions/xxxxx-xxxx-xxxx-xxxxx-xxxxxxxresourceGroups/management/providers/Microsoft.Network/networkInterfaces/myvm-nic was not found. Please make sure that the referenced resource exists, and that both resources are in the same region.

However, creating NIC manually in portal, allows to have it in myVMGroup and then deploy VM using this NIC correctly.

tjprescott commented 7 years ago

Hi @SebastianFyda. When you supply names for parameters, the CLI assumes that all of those named resources exist in the resource group you specify with --resource-group/-g. In your case, you would need to specify the subnet by ID.

From the help text:

--subnet            [Required]: Name or ID of an existing subnet. If name specified, also
                                    specify --vnet-name.

So you would need to specify the fully qualified subnet ID and not include vnet-name (or you will get an error). If that doesn't work, please reopen.

ghost commented 7 years ago

Yeah, but that requires unecessary complexity, like getting subscription ID and constructing complex string. Powershell has an option to specify --VirtualNetworkResourceGroup while craeting VM, which is consistent with how Portal operates (during NIC creation you just select existing resources by names). I would suggest adding --vnet-resource-group switch.

tjprescott commented 7 years ago

That is what Xplat does and we find it adds far too much clutter to the parameter space and help. IDs can be copied/pasted easily or programmatically retrieved with a command like: az network vnet show -g {rg} -n {name} --query id -otsv

Also, the ID is returned in create queries, so you don't necessary need to make a separate command to get the ID--you can simply piggyback off the create command.