The current ‘AddArmRole’ function appears to be a blocker on the advanced installation script. With a recent customer, we built a brand new app registration and utilized the default ‘deploy-az.ps1’ file from the Nerdio Manager initial install and it failed at that step. When adding a ‘try-catch’ call, it allows the continuation of the script. Thinking that this try-catch should be implemented in the script, or something similar, so the script can continue and inform the admin to proceed with a manual RBAC assignment of the SPN to the subscription.
Existing
function AddArmRole($objectId, $scope, $roleName) {
$role = Get-AzRoleAssignment -ObjectId $objectId -Scope $scope | Where-Object {$_.Scope -eq $scope -and $_.RoleDefinitionName -eq $roleName }
if (!$role) {
New-AzRoleAssignment -ObjectId $objectId -Scope $scope -RoleDefinitionName $roleName
}
}
Proposed
function AddArmRole($objectId, $scope, $roleName) {
$role = Get-AzRoleAssignment -ObjectId $objectId -Scope $scope | Where-Object {$_.Scope -eq $scope -and $_.RoleDefinitionName -eq $roleName }
if (!$role) {
try {
New-AzRoleAssignment -ObjectId $objectId -Scope $scope -RoleDefinitionName $roleName -ErrorAction Stop
} catch {
Write-Host "Failed to assign role '$roleName' to object '$objectId' at scope '$scope': $($_.Exception.Message)"
}
}
}
Comments (3 comments)