Get Azure resources associated with a subnet through Azure Resource Graph Query

4.8k views Asked by At

I am looking to fetch all resources associated with a subnet. I could find references oh how to do it the other way around (fetch a particular resource and it includes the subnet it is associated with), but can't find any documents where we can fetch all resources linked with a subnet.

My ultimate goal is to fetch all azure resources which use a particular network security group. That led me to the above question.

From another question I understand I can use a REST Api to get details for a specific virtual network. How to check is subnet allocated with another resource in azure using Fluent API or management API?. I would appreciate if someone could suggest anyway to achieve this.

Thanks in advance.

2

There are 2 answers

1
Godson On BEST ANSWER

Found the answer myself :p. You get the associated devices within the subnet details along with other details on getting virtualnetworks.

Resource graph query:

resources
| where type =~ "microsoft.network/virtualnetworks"

properties->subnets->properties->ipConfigurations

The ipConfigurations are the connected devices.

0
Smug On

It is here under Virtual Network.

enter image description here