Search code examples
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:

  • vm1: dynamic ip - 10.0.0.2, requested static ip 10.0.0.9
  • vm2: dynamic ip - 10.0.0.3, requested static ip 10.0.0.15
  • vm3: dynamic ip - 10.0.0.4, requested static ip 10.0.0.16
  • vm4: dynamic ip - 10.0.0.5, requested static ip 10.0.0.17
  • vm5: dynamic ip - 10.0.0.6, requested static ip ---------
  • vm6: dynamic ip - 10.0.0.7, requested static ip 10.0.0.19
  • vm7: dynamic ip - 10.0.0.8, requested static ip 10.0.0.20
  • vm8: dynamic ip - 10.0.0.9, requested static ip 10.0.0.21
  • vm9: dynamic ip - 10.0.0.10, requested static ip 10.0.0.8
  • vm10: dynamic ip - 10.0.0.11, requested static ip 10.0.0.6

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.