In Bicep, I can use subscriptionResourceId()
or managementGroupResourceId()
to refer to a resource at the subscription or management group level, respectively.
In the following code, I’m using subscriptionResourceId()
to create a (RBAC) role assignment at the subscription level for a system-assigned managed identity and an Azure Key Vault:
resource keyVaultRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(
subscription().id,
subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')
)
scope: keyVault
properties: {
principalId: appServiceApp.identity.principalId
roleDefinitionId: subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
'4633458b-17de-408a-b874-0445c86b69e6'
)
}
}
How would I get the resource’s resource group ID? The resourceId()
function depends on the scope of the deployment, and so is ambiguous
2
Answers
Here is the updated code to fetch the
resourcegroup ID
from a resource (app service) and assign a role to the app service identity at the resource group level.Output:
After running the code, the role assignment has been assigned at the resource group level for the system-assigned managed identity.
If you’re operating within the scope of your resource, then you can just use
resourceGroup().id
to get the resource’s resource group ID right?