Richard Wolford
Richard Wolford

Reputation: 453

Can't create azure virtual machine using the cli

I have a resource group with all of my networking in it. I need to create a VM in another resource group but using the vnets/subnet in the other resource group. It is failing miserably at the cli. Here's the command I'm using:

az vm create --name vm-jmp-poc-e --resource-group rg-mgmt-poc-eastus-001 --public-ip-address "" --image Win2016Datacenter --data-disk-sizes-gb 10  --admin-user adminuser --admin-password ThisIsThePass123$ --availability-set av-cpe-poc-eastus-001  --subnet subscriptions/938b61f6-ecac-4c61-ad3b-7e856c377660/resourceGroups/providers/Micosoft.Network/virtualNetworks/rg-sql-cpe-poc-eastus-001/vnet-primary-poc-eastus-001/subnets/snet-mgmt-poc-eastus-002 --location eastus

Here is the error:

ValidationError: incorrect usage: --subnet ID | --subnet NAME --vnet-name NAME

Please help!!!

Upvotes: 2

Views: 1183

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28204

The problem is that you have provided a wrong subnet ID, the correct format is that

/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Network/virtualNetworks/<vnetName>/subnets/<subnetName>

You can get the subnet ID via

az network vnet subnet show -g <rgName> -n <subnetName> --vnet-name <vnetName>  --query id -o tsv

You lack the resource group name in your providing subnet ID.

subscriptions/xxxx/resourceGroups/providers/Micosoft.Network/virtualNetworks/rg-sql-cpe-poc-eastus-001/vnet-primary-poc-eastus-001/subnets/snet-mgmt-poc-eastus-002

Result

enter image description here

Upvotes: 3

Related Questions