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