Hi FLOER, Clément,
Yes, you can absolutely use a userAssigned ManagedIdentity without relying on environment variables. I know this can be a bit confusing at first, so I hope the example below helps make things clearer. Here’s the code to retrieve all the user-assigned identities attached to a resource group:
from azure.identity import DefaultAzureCredential
from azure.mgmt.msi import ManagedServiceIdentityClient
subscription_id = "<subscription_id>" # Replace with your subscription ID
credential = DefaultAzureCredential()
client = ManagedServiceIdentityClient(credential,subscription_id )
resource_group = "<resource_group_name>" # Replace with your resource group name
for identity in client.user_assigned_identities.list_by_resource_group(resource_group):
print(identity.id)
These are the dependencies: → pip install azure-mgmt-msi azure-identity
From here, you can integrate the identities into your code by filtering them based on whatever identifier fits your requirements.
Feel free to accept this as an answer if it helps.
Thank you for reaching out to The Microsoft Q&A Portal.