Reputation: 11
I need to get a list of public ips along with subsciption name, resource type (such as vm, application gateway, elb) in Azure using Azure Resource Graph. I would also like to display the public ip addresses as well.
This is my draft but I don't know how list other resources:
Resources
| where type =~ 'microsoft.compute/virtualmachines'
|project name, OS=tostring(properties.storageProfile.osDisk.osType), location,
ipid = tolower(tostring(properties.networkProfile.networkInterfaces[0].id))
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/networkinterfaces'
| project ipid = tolower(id), elasticPoolName = name,
publicIPid = properties.ipConfigurations[0].properties.publicIPAddress.id)
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/applicationGateways'
| project name, publicIP
on ipid
| project-away ipid
| project name, OS, location, pubipid=tolower(tostring(publicIPid))
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/publicipaddresses'
| project pubipid = tolower(id), publicIP = properties.ipAddress)
on pubipid
| project-away pubipid
| project name, publicIP, OS, location
Upvotes: 1
Views: 2025
Reputation: 11421
You can use the below query to get the associated resource providers for all the IP addresses:
Resources
| where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress)
| project name,id= split(properties.ipConfiguration.id,"providers",1),ip_address=properties.ipAddress
Output:
Note:
- As You can see in the above image , we get a output of providers with the name in the id part for example
/Microsoft.Network/loadBalancers/kubernetes/frontendIPConfigurations/0713fba8-23fa-43bc-a003-b4197500b399
, then it means that the Public IP is associated with aLoad balancer
with namekubernetes
as shown in 1.- If the association is with network interface , then the network interface might be associated with a Compute resource (like VM etc) or a DNS as shown in 2.
- If it is not associated with any resource then it gives back
null
as shown in 3.- In 4 it is being used by Bastion Host.
- In 5 its being used by a VNET Gateway.
Upvotes: 1