Is it possible to use Azure Policy to apply CanNotDelete locks at resource level?

Chad Woodhead 21 Reputation points
2021-10-13T18:52:32.337+00:00

I am trying to use Azure Policy to track compliance of resources with or without locks on and if a resource doesn't have a lock on, then apply the lock. I have been able to get Azure Policy to apply CanNotDelete locks at the ResourceGroup level, however I don't want to apply them at that level and instead want to apply them at the resource level (storage accounts, key vault, etc.). Is it possible to use Azure Policy as the method to apply locks at resource level?

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
793 questions
0 comments No comments
{count} votes

Accepted answer
  1. Grmacjon-MSFT 16,011 Reputation points
    2021-10-14T04:16:25.073+00:00

    Hi @Chad Woodhead ,

    Yes, it is possible to use Azure Policy as the method to apply locks at the resource level. Please read this documentation: Lock Resources to Prevent Unexpected Changes on how to do this in the Azure portal.

    You can also use Azure PowerShell to accomplish this as well. To lock a resource, provide the name of the resource, its resource type, and its resource group name.

    New-AzResourceLock -LockLevel CanNotDelete -LockName LockSite -ResourceName examplesite -ResourceType Microsoft.Web/sites -ResourceGroupName exampleresourcegroup  
    

    Hope that helps. Please let us know if you have further questions

    Thanks,
    Grace

    --If the reply is helpful, please Upvote and Accept as answer--


0 additional answers

Sort by: Most helpful