@KalyanChanumolu-MSFT Do we run this on azure shell? By passing with respective arguments?
How to check is subnet allocated with another resource in azure using Fluent API or management API ?
I am creating Application gateway using ARM templete now I want to check after select the virtual network subnet should not be allocated any other resource if allocated then show the message like Subnet must have only have Application Gateway.
2 answers
Sort by: Newest
-
-
KalyanChanumolu-MSFT 8,316 Reputation points
2021-02-24T11:03:57.067+00:00 @Dnyaneshwar Surywanshi Thank you for reaching out.
We sincerely apologize for the delay in getting back to you.You can use the IpConfigurations property to check if the subnet is already associated with with any other resource.
var network = await azure.Networks.GetByIdAsync("/subscriptions/XXXXX-c5b6-44fb-b5ba-XXXXX/resourceGroups/XXXX-testing/providers/Microsoft.Network/virtualNetworks/vnet90e998400c370f"); foreach (var subnet in network.Inner.Subnets) { if (subnet.IpConfigurations == null) { Console.WriteLine("Subnet is not associated"); } else { Console.WriteLine("Subnet is already associated"); } }
Please let us know if you have any further questions.
----------
If an answer is helpful, please "Accept answer" or "Up-Vote" for the same which might be beneficial to other community members reading this thread.