I have the following bicep file
param accountName string
param roleId string
param principalId string
resource account 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
name: accountName
}
resource roleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
scope: account
name: roleId
}
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2023-04-15' = {
scope: account
name: guid(account.id, principalId, roleDefinition.id)
properties: {
roleDefinitionId: roleDefinition.id
principalId: principalId
principalType: 'ServicePrincipal'
}
}
When executing this the error is that it cannot find the account {accountName} in the resource-group that it's running from, however I am trying to set the roleAssignment on a storageAccount that already exists in another subscription/resource group. Since storage account names are unique I would think this should work?
You should use Bicep Modules here. combine
modules+scopetwo keywords help you to implement nested deployment accross resources groups.For you circumstance, I have coded a sample and tested.
main.biceproleAssign.bicepdeploy.ps1