Search code examples
azureazure-cli

How to create a Azure Service Principal with more than one subscription at its scope using Azure CLI?


Basically the title. I want to create a service Principal who has access to more than 1 subscription.

I can create a service principal with access to one subscription as follows:

az ad sp create-for-rbac --name <service_principal_name> --role Contributor --scopes /subscriptions/<subscription_id>

But I need 2 subscriptions as scope.


Solution

  • The scopes parameter is a space-separated list of scopes.

    --scopes

    Space-separated list of scopes the service principal's role assignment applies to. e.g., subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup, /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM.

    as stated in the documentation