To assign the "Cosmos DB Built-in Data Contributor" role to a Logic App's system-assigned managed identity in Azure Cosmos DB using an Azure Bicep script, you can follow these steps:
- Retrieve the roleDefinitionId for the "Cosmos DB Built-in Data Contributor" role. You can use the Azure CLI or Azure PowerShell to get the role definition ID.
Using Azure CLI:
Bash
az cosmosdb sql role definition list --account-name <cosmos-db-account-name> --resource-group <resource-group-name> --query "[?roleName=='Cosmos DB Built-in Data Contributor'].id | [0]"
Using Azure PowerShell:
(Get-AzRoleDefinition | Where-Object {$_.Name -eq "Cosmos DB Built-in Data Contributor"}).Id
- Once you have the roleDefinitionId, you can use it in your Bicep script to create the role assignment:
Bicep
resource cosmosDBRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2021-10-15' = {
name: 'cosmosDBRoleAssignment'
parent: cosmosDB
properties: {
principalId: '<logic-app-system-assigned-identity-object-id>'
roleDefinitionId: '<role-definition-id>'
scope: '/'
}
}
Replace
Make sure you have the necessary permissions to create role assignments in Azure Cosmos DB.