Next available subnet finder

Kolloju Srinath Chary 1 Reputation point

I need to programmatically find new subnet block with specific address space from a vnet that has multiple subnets with different address spaces.

Is there any way via code or azure devops

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,298 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,194 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ChaitanyaNaykodi-MSFT 24,666 Reputation points Microsoft Employee

    @Kolloju Srinath Chary ,

    Welcome to the Microsoft Q&A forum.

    As discussed in a similar thread here currently there is no out of the box functionality offered to do this particular automation.

    Although you can try your own custom automated solution here. Azure offers management rest API calls which can fetch you details about a virtual network, for example you can fetch the VNET details such as Address Space, Subnet name, subnet address space by performing this rest API call where you can write code to parse the string received to fetch required details and use the details to calculate the next subnet available (sample code for reference) you can then do a PUT API operation to add the particular subnet on Azure.
    You can run the above code on Azure using Function Apps, for example you can create a blob triggered function app where you can upload a file containing meta data required (like virtual network names etc.) to run API calls above which will trigger a function app which will run the code mentioned above. I could not find a specific sample for this solution, but you can go through these samples for reference.

    Instead of the Management REST API Calls you can also use PowerShell Commands as Azure Function Apps support PowerShell.

    Please let us know if you have any additional questions above. Thank you!

    0 comments No comments

  2. Bas Pruijn 951 Reputation points

    I understand the issue. However, the root cause for this is a lack of network management (in the past). Wouldn't it be better to start managing the network/subnet setup first? You could achieve this by adding a new IP range to the VNET, define new subnets and move your resources to these new subnets. Once you are in control of what IP ranges are used in each vnet, adding new subnets is easy.

    0 comments No comments