Bicep can be used to create a role assignment as follows:
resource RoleAssignment 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = {
name: guid(managementGroup().id, RoleDefinitionId, principalId)
properties: {
roleDefinitionId: roleDefinition.id
principalId: principalId
principalType: principalType
}
}
Where the principal type is ‘ServicePrincipal’, it seems the application id from the Enterprise Application page of the Azure portal is required:
Does anyone know how to acquire this programatically? If it’s not possible using bicep then perhaps PowerShell?
2
Answers
To get the
Application ID
of service principal via PowerShell, you can make use of below command:I tried to reproduce the same in my environment and got below results:
I have one service principal named
ClientApp
and got the Application ID of it successfully as below:Response:
You can use the output of resource like:
So you can use in role assigment resource: