I am testing a python script that will check the tags of each resource in Azure. This script gets the list of resources from a CSV file where resources from different tenants are listed.
For testing purpose I am using my Azure account which is prensent in one tenant only so the script fail when I get to the resources in the other tenants.
What account/solution should I use to get information from different tenants from my script ?
Any ideas ?
I tried to connect with az login into different accounts on each tenant but the token that is kept is only the one of the last account where I logged in, so it is impossible to login into multiple accounts with Azure CLI.
I guess it would be the same with service principal as it is known in only one tenant.
I ended up connecting to each tenant separately into my script.
if current_tenant != tenant:
if tenant == 'PROD':
print("login into azure CORP")
os.system('az login --tenant xxxx')
elif tenant == 'HML':
print("login into azure hml")
os.system('az login --tenant yyyyyyy')
elif tenant == 'DEV':
print("login into azure dev")
os.system('az login --tenant ccccccc')
elif tenant == 'REC':
print("login into azure Rec")
os.system('az login --tenant wwwwwwwww')