I created virtual network and I want to deploy a new VM to this virtual network. The network
I tried to create the VM using this command:
az vm create --resource-group myGroup --name VMTestNet1 --location eastus --image eastus1Image --vnet-name eastusVNet1 --admin-username azureuser --size Standard_F4S --public-ip-address ""
I got this exception:
Deployment failed. {
"error": {
"code": "InUseSubnetCannotBeDeleted",
"message": "Subnet GatewaySubnet is in use by /subscriptions/subscriptionId/resourceGroups/Automationsystem/providers/Microsoft.Network/virtualNetworkGateways/eastusGW/ipConfigurations/vnetGatewayConfig0 and cannot be deleted.",
"details": []
}
}
How can I deploy my VM to an existing Virtual network?
I have successfully reproduced the issue using the subnet which are used by another VM and non-gateway subnet. So this issue may caused by Another instance was using the subnet and you didn’t supplied this subnet information when you created a new VM. We can fix it supply your subnet information in your vnet when you create a new VM.
Then we can create a new vm and associate it to exiting Vnet like this:
I test these script and it worked.