question

DnyaneshwarSurywanshi-3200 avatar image
0 Votes"
DnyaneshwarSurywanshi-3200 asked VenkataSuri-4408 answered

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.

69497-subnetappgw.png


azure-virtual-networkazure-application-gateway
subnetappgw.png (34.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

KalyanChanumolu-MSFT avatar image
0 Votes"
KalyanChanumolu-MSFT answered

@DnyaneshwarSurywanshi-3200 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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VenkataSuri-4408 avatar image
0 Votes"
VenkataSuri-4408 answered

@KalyanChanumolu-MSFT Do we run this on azure shell? By passing with respective arguments?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.