question

BrianBertrand-5876 avatar image
0 Votes"
BrianBertrand-5876 asked BrianBertrand-5876 commented

How do I add managed identity to azure batch pool via python?

I'm currently creating batch pools using azure.batch.models.PoolAddParameter()

I'm wondering how to assign a managed identity to the pool using this class. I found azure.batch.models.BatchPoolIdentity(), but cannot figure out how to assign it to the pool.

Any help would be greatly appreciated.

azure-batch
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

prmanhas-MSFT avatar image
1 Vote"
prmanhas-MSFT answered BrianBertrand-5876 commented

@BrianBertrand-5876 Apologies for the delay in response and all the inconvenience caused because of the issue.

To assign managed identities to pools you need to use the management client instead of the normal batch service client, this is so that requests are routed through ARM which supported managed identity. Here is some untested sample code in Python but should work with minimal tweaks:



from azure.identity import DefaultAzureCredential
import azure.mgmt.batch
import azure.mgmt.batch.models

client = azure.mgmt.batch.BatchManagement(credential=DefaultAzureCredential(), subscription_id="test")

sample_identity = azure.mgmt.batch.models.BatchPoolIdentity(
type=azure.mgmt.batch.models.PoolIdentityType.USER_ASSIGNED,
user_assigned_identities={
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identientityName": None
}
)
params = azure.mgmt.batch.models.Pool(identity=sample_identity)

client.pool.create("resource", "account", "poolName", params)

Hope it helps!!!

Please "Accept as Answer" if it helped so it can help others in community looking for help on similar topics.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

We ended up creating our pools manually, but this works.
Thanks so much for the help!

0 Votes 0 ·