1

I have multiple subscriptions in an Azure tenant and I'd like to list all resources (IP addresses, VMs, etc) in the tenant. Is this the same as listing the resources from all subscriptions?

We can easily list all resources in a subscription with a service principal to access it. However, there are some problems when you try to do this for a tenant. It it possible to create a service principal or an equivalent that applies to the whole tenant or to all the subscriptions in the tenant (depending on the answer to the first question) that would allow to list all resources with a script?

EDIT: Actually, what I'm precisely trying to do is to list all public IPs in a Azure tenant with a python script:

def get_public_ips(self):
    """@returns: All public ip adresses in the ressource defined by the service principal"""
    ips=[]
    rmc = get_client_from_auth_file(ResourceManagementClient, auth_path=PATH+"azure_creds.json")
    for r in rmc.resources.list(filter="resourceType eq 'Microsoft.Network/publicIPAddresses'", expand='True'):
        #There were no way to get the ip adress directly...
        ip = rmc.resources.get_by_id(r.id, "2019-09-01")
        ips.append(ip.properties['ipAddress'])
    return common.sanitize_ips_list(ips)

The script can already list all IPs but it is using a service principal to authenticate: https://learn.microsoft.com/en-us/python/api/msrestazure/msrestazure.azure_active_directory?view=azure-python

I wonder how to do the same thing with a whole tenant. Is this event possible? Would the same script script work by simply using another way to authenticate, i.e.by using an authentication entity that has reading rights on the whole resources of the tenant?

Thanks

Michael Easter
  • 23,733
  • 7
  • 76
  • 107
  • You may want to add what you have attempted so far. Actual code or screen shots to give people better context. – BernardA Nov 12 '19 at 20:59
  • Just to be clear: are you trying to list all resources in your tenant, ip addresses or something else? Is your question specific to authentication/authorization? Let me know. Thanks. – LMG Nov 13 '19 at 02:00
  • I'm trying to list all public ip adresses in my tenant, but I think the answer has something to do with authentification since I'm able to list all IP of a Subscription with an associated service principal. I'd like to do exactly the same thing with an whole tenant. – Mathieu Béland Nov 15 '19 at 14:32

2 Answers2

1

you can use tags and filter by tags

https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-using-tags

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
-1

The following command will return you all resources in your tenant:

az resource list

The following command will return you all public ip addresses in your tenant:

az resource list --resource-type 'Microsoft.Network/publicIPAddresses'
az resource show --ids '<resource id>'

Field 'properties.ipAddress' is likely what you are looking for.

LMG
  • 1,330
  • 11
  • 21
  • This returns resources in *one subscription*, not tenant wide. The question pertains to tenants with multiple subscriptions. – Jepper Oct 22 '21 at 10:00