Alex D
Alex D

Reputation: 828

Azure creating VM on existing VNET with multiple subnets

I have multiple VMs already in the same VNET. When I create a new VM trying to use that same VNET I get an error. I do not want to delete existing subnets (4) already in the vnet. All I want to do is add a new vm to the already existing vnet with a new subnet attached to it. I have seen similar posts but none show how to deal with multiple existing subnets.

This is the error

Subnet Foo2Subnet is in use by /subscriptions/<subid>/resourceGroups/foo-westus2/providers/Microsoft.Network/networkInterfaces/Foo2VMNic/ipConfigurations/Foo2 
 cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.

here is how I am creating a new vm.

'az vm create ' \
    '--resource-group {resourceGroupName} ' \
    '--name  "{serverName}" ' \
    '--image "UbuntuLTS" ' \
    '--use-unmanaged-disk ' \
    '--vnet-name foo2VNET ' \
    '--subnet test1' \
    '--public-ip-address "" ' \
    '--storage-sku Standard_LRS ' \
    '--admin-username {user_name} ' \
    '--admin-password "{password}" ' \
    '--size "{vm_size}" ' \
    '--custom-data  "" --no-wait'

Upvotes: 0

Views: 1418

Answers (1)

4c74356b41
4c74356b41

Reputation: 72171

What is happening - az vm create is attempting to perform a create vnet with this subnet only (so overwrite your existing vnet configuration). Nothing you can really do about this, what you can do is precreate the subnet in the vnet, after that your command will work.

Upvotes: 1

Related Questions