fascynacja
fascynacja

Reputation: 2826

how to retrieve all resources under given subnet using Azure Resource Graph Explorer query

I am using Azure Web App services, which have configured virtual network integration with an outbound subnet: enter image description here

I would like to list all resources which are associated with given subnet: "snet-dev". I have created a query and run in the Azure Resource Graph Explorer: enter image description here

query is:

Resources
| where type =~ "microsoft.network/networkinterfaces"
| extend subnetId = tostring(properties.ipConfigurations[0].properties.subnet.id)
| where subnetId contains "snet-dev"  
| project id, name, resourceGroup, location, subnetId

Unfortunately no results are fetched. I have tried to run the query without the "where" but then I am getting far to many results to manualy find the resources with given subnet.

How to write a query which will return all linked resources to a given subnet?

Upvotes: 0

Views: 295

Answers (1)

Sridevi
Sridevi

Reputation: 22352

I have few Azure Web App services configured virtual network integration with an outbound subnet named "snet-dev" like this:

enter image description here

Initially, I too got null results when I ran same query as you in my environment like this:

Resources
| where type =~ "microsoft.network/networkinterfaces"
| extend subnetId = tostring(properties.ipConfigurations[0].properties.subnet.id)
| where subnetId contains "snet-dev"  
| project id, name, resourceGroup, location, subnetId

Response:

enter image description here

To retrieve all Azure Web App resources under subnet named "snet-dev" using Azure Resource Graph Explorer, you can run below query:

resources
| where type =~ "microsoft.web/sites" // Search for Azure Web Apps
| extend subnetID = tostring(properties.virtualNetworkSubnetId)
| where isnotempty(subnetID) 
| extend extractedSubnetName = tostring(split(subnetID, '/')[10]) // Extract subnet name from the full virtualNetworkSubnetId path
| where extractedSubnetName == "snet-dev" 
| project webAppId = id, webAppName = name, subnetID, extractedSubnetName

Response:

enter image description here

Upvotes: 1

Related Questions