We have discussed how we can setup system assigned identity and use it to assign roles in Azure app Config service in the post "Role Assignment with Azure Bicep". IF we are using managed identity as system assigned each of the web app, function app will have different identity and granting permissions in a service such as Azure App Config service would need to add multiple role assignement, assigning each app system assigned managed identity with the required role to read configs. However, if you use a single user assigned identity to all the app service apps, you can use single role assignment in the required service. Let's explore how to create and assign user assigned ident step by step in Azure Bicep infrastructure as code.
User assigned identity can be defined as below in Bicep. We have to pass a name for the user assigned identity. We are using user assigned identity Id to assign it to an app service app. However, note that we are having service principal Id of the user assigned identity added as output variable, which is required to use for role assignement.
param userAssignedMangedIdentityName string param location string resource UserAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { name: userAssignedMangedIdentityName location: location } output managedIdentityId string = UserAssignedIdentity.id output managedIdentityServicePrincipalId string = UserAssignedIdentity.properties.principalId
The Id of user assigned identity should be used in web app module to assign it to the web app. Note below we have used the UserAssignedIdentity parameter and assigned it to a web app. Unlike in the post where we used system assigned managed identity, we are not using output variable service principal Id of app service app here as there is no such value since we use user assigned identity.
We need app service plan module as well.
Then in the main Bicep we can use modules defined above and create a app service app which is using user assigned identity.
We can execute the Bicpe using a pipeline as described here or using a command such as below in PowerShell using Azure CLI.
az deployment sub create --name 'userassignedidsample' --location eastus --template-file main.bicep --parameters rgLocation='eastus'
Once the deployment completes you can see the app service is assigned with user assigned identity.
No comments:
Post a Comment