azureazure-virtual-machineazure-devtest-labs

Azure - create multiple Virtual Machines with static addresses - conflicts


I'm working on a project in which we create labs (for students) in which users can create virtual machines and specify that they ought to have static ip addresses. The problem is that when a virtual machine is created on Azure, it alwayas has a dynamic ip address and only then can be assigned a static one.

Is there a way to make it possible to allocate multiple simultaneously created virtual machines with static ips that were chosen by users? We do store these ip addresses in the database so before the conflict happens in Azure, we can detect it on the database level but it's not enough.

Why? Because if we create 10 virtual machines at the same time, all of them with specific static ips, some may be created with conflicting dynamic addresses:

After creation of these vms, when trying to assign 10.0.0.9 to vm1, there will be an error because vm8 has this ip address (although it doesn't want it either, it wants to change to 10.0.0.8 which is taken as well).

I guess a centralized point for creation would be perfect but unless there is something like that on Azure, I don't think it can be done on our end.

Any thoughts?


Solution

  • In the Azure portal, if you use the UI to create VMs directly, a lot of steps will be done by Azure in the backend so that you cannot control the creation. I suggest that you can use the Azure Template or Azure CLI and Azure PowerShell script to achieve it. You can select one of the above three methods. Then you can create the NIC with the Static allocate method.