What takes precedence - Azure Policy or Locks

Shridhar Srinivasan 220 Reputation points
2023-07-17T11:22:39.1533333+00:00

I have a Resource Group named RG1. I have a Read-only Lock applied to RG1.

I have a Policy assigned to RG1 which has "allowed resource types" for "Virtual Machines".

Can I create a VM in RG1 ?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,058 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
1,020 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andrew Blumhardt 10,051 Reputation points Microsoft Employee
    2023-07-17T13:14:29.7133333+00:00

    I assume the lock wins but I recommend devising a test to verify if needed.


  2. kobulloc-MSFT 26,811 Reputation points Microsoft Employee Moderator
    2023-07-26T01:45:04.82+00:00

    Hello, @Shridhar Srinivasan !

    Can I deploy VMs into a resource group with a read only lock if there is a policy that has allowed resource types of virtual machines?

    The short answer is "no", but this is because there isn't a policy that explicitly allows resource creation. Rather, allowed resource types works by denying resource types that are not explicitly listed as allowed resource types:

    User's image

    When we look at the policy in more detail, we can see an if/then statement that matches the description of the policy:

    Allowed Resource Type (Deny): Defines the resource types that you can deploy. Its effect is to deny all resources that aren't part of this defined list.

    User's image

    When testing this, we see that VM creation is not allowed in a read only resource group:

    User's image


    I hope this has been helpful! Your feedback is important so please take a moment to accept answers.

    If you still have questions, please let us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.