Executing New-AzurermResourceLock on Azure Automation results in an error
Cmdlet(s)
New-AzurermResourceLock (executed as Service Principal) on Azure Automation
PowerShell Version
Azure Automation Runbook (PowerShell)
Module Version
AzureRM.Resources Version: 3.6.0
Description
When executing New-AzurermResourceLock in an Azure Automation Runbook an error occured.
Debug Output
Logging in to Azure... New-AzurermResourceLock : The pipeline has been stopped. At line:10 char:1
- New-AzurermResourceLock -LockLevel CanNotDelete -LockNotes "No deleti ...
-
+ CategoryInfo : CloseError: (:) [New-AzureRmResourceLock], PipelineStoppedException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceLockCmdlet
New-AzurermResourceLock : AuthorizationFailed : The client 'a073fd36-99e1-4a78-b6cb-840b55b45f82' with object id 'a073fd36-99e1-4a78-b6cb-840b55b45f82' does not have authorization to perform action 'Microsoft.Authorization/locks/write' over scope '/subscriptions/9b7bbcdc-0ef4-4fd7-b35b-f80193f65de2/resourceGroups/YOG001/providers/Microsoft.Authorization/locks/ResourceGroupLock'. At line:10 char:1
- New-AzurermResourceLock -LockLevel CanNotDelete -LockNotes "No deleti ...
-
+ CategoryInfo : CloseError: (:) [New-AzureRmResourceLock], ErrorResponseMessageException + FullyQualifiedErrorId :
AuthorizationFailed,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceLockCmdlet
Script/Steps for Reproduction
$ServicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
Write-Output "Logging in to Azure..."
Add-AzureRmAccount
-ServicePrincipal
-TenantId $servicePrincipalConnection.TenantId
-ApplicationId $servicePrincipalConnection.ApplicationId
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint | Out-Null
New-AzurermResourceLock -LockLevel CanNotDelete -LockNotes "No deleting !" -LockName "ResourceGroupLock" -ResourceGroup "YOG001" -Force
@ravbhatnagar Hey Gaurav, would you mind taking a look at this issue?
Hello, some news about this problem ? It looks like to that problem : https://github.com/Azure/azure-powershell/issues/3549
Still the same error after update the module AzureRM.Resources with the version 4.1.0
@YoannGUILLO - What permissions were granted to the Service principal when it was created? From error message above, it looks like the service principal does not have permission to perform a write operation for 'Microsoft.Authorization/locks/write' over the indicated scope.
I used the azure automation run as account created by default with my automation account, role assigned by default was contributor, I've set to owner and it work now. Incident can be closed thank for your support.
Thanks for confirming! Closing this issue.