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.

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.

@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.
6 people are following this question.