Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

networking - 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!!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...