Loading...

Quickstart: DenyAction Effect in Azure Policy

Quickstart: DenyAction Effect in Azure Policy

Background

 

Azure policy introduced a new policy effect named 'DenyAction' recently, which enables the user to block requests on intended action to resources in case the critical resources are changed. This article introduces the 'DenyAction' effect and the expected behaviors with a demo.

 

Please note that the DenyAction effect is now in public preview.

 

We will cover two sections in this article:

  1. Policy definition.
  2. The expected behavior of the effect.

 

Policy Definition

 

The DenyAction effect is designed to block the operation of intended action to modify specific resources. Currently, only the DELETE action is supported. When a request is made to delete a resource, which is in the scope of a DenyAction Policy assignment, the request will be blocked. To introduce more details about this effect, let's start by creating a policy definition as an example.

 

Suppose we are creating a DenyAction policy to protect resources from accidental deletion with the following business requirement:

 

  1. The resource type to be protected is virtual machine.
  2. Only the resources with "environment: prod" tags are not allowed for deletion.
  3. Both virtual machine and its resource group should be protected from deletion.

 

To meet the requirement above, we can write policy rules as shown below and assign the policy to the specific scope:

 

 

 

{ "mode": "Indexed", "policyRule": { "if": { "allOf": [ { "field": "type", "equals": "Microsoft.Compute/virtualMachines" }, { "field": "tags.environment", "equals": "prod" } ] }, "then": { "effect": "DenyAction", "details": { "actionNames": [ "delete" ], "cascadeBehaviors": { "resourceGroup": "deny" } } } }, "parameters": {} }

 

 

 

Hints:

The section of cascadeBehaviors is optional. This is to define what behaviour will be followed when the resource is implicitly deleted by the removal of a resource group. Only the indexed resources are supported for this section. Once the section is added, the policy mode should be set to 'Indexed' as well.

 

An index resource refers to the resource that supports tags and locations. For more details about the index resource, please refers to the document: https://learn.microsoft.com/en-us/azure/governance/policy/concepts/definition-structure#resource-manager-modes

 

In this case, we will set the cascadeBehaviors as 'deny' because we do not want to remove the protected VM resources when deleting the resource group where they reside. Therefore, the policy will follow the 'deny' behaviour when proceeding with the resource group deletion request.

 

 

Expected Behavior

Now that the custom policy with the DenyAction effect has been assigned and taking effect, let’s explore some scenarios of entity deletion and the expected behaviors.

 

Scenario 1. Resource Deletion

If the VM resource is deleted directly, it would fail with 403(Forbidden) and the following notification can be found in the activity log.

 

jiayiwu_0-1672300243162.png

 

Scenario 2 Resource Group Deletion

If a user tries to delete the resource group that contains the VM resource, the request will fail. This is because I set the cascadeBehaviors is set to 'deny' in the above policy. Therefore, the policy would deny the request of resource group deletion. As a result, nothing will be deleted. The message below can be found in the activity log:

 

jiayiwu_1-1672300243169.png

 

 

However, if the cascadeBehaviors is set as 'allow', the policy will follow the 'allow' action when the resource is being implicitly deleted by the removal of a resource group. Which means, the resource group and all the resources within the same resource group will be deleted.

 

 

 

"then": { "effect": "DenyAction", "details": { "actionNames": [ "delete" ], "cascadeBehaviors": { "resourceGroup": "allow" } } }

 

 

 

 

jiayiwu_2-1672300243171.png

 

Scenario 3. Subscription Deletion

The policy won't block removal of resources that happens during a subscription deletion.

 

Scenario 4. Child resource Deletion

Child resource are the resource that exist only within the context of another resource. In this demo, a virtual machines extension resource is a child of the virtual machine, whom is the parent resource.

 

jiayiwu_3-1672300243172.png

The policy is assigned to protect the VM resource '5plus1TestVM01' only (parent resource).  If the entity being deleted is 'AzurePolicyforWindows'(child resource), then the child resource will be deleted, and the parent resource remains.

 

Please read the document below if you want to learn more about the DenyAction effect: https://learn.microsoft.com/en-us/azure/governance/policy/concepts/effects#denyaction-preview

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Give your Foundry Agent Custom Tools with MCP Servers on Azure Functions

Learn how to connect your MCP server hosted on Azure Functions to Microsoft Foundry agents. This post covers authentication options and setup ...

1 day ago

Azure Data Factory Tips for Reliable Microsoft Dynamics 365 CE and Dataverse Integrations

Reliable integrations between Microsoft Dynamics 365 Customer Engagement and external systems can become challenging. This is especially true ...

1 day ago

Scalable AI with Azure Cosmos DB: Tredence Intelligent Document Processing (IDP) | March 2026

Azure Cosmos DB enables scalable AI-driven document processing, addressing one of the biggest barriers to operational scale in today’s enterpr...

2 days ago

Announcing the end of support for Node.js 20.x in the Azure SDK for JavaScript

After July 9, 2026, the Azure SDK for JavaScript will no longer support Node.js 20.x. Upgrade to an Active Node.js Long Term Support (LTS) ver...

2 days ago

MCP Apps on Azure Functions: Quickstart with TypeScript

Learn how to build and deploy MCP (Model Context Protocol) apps on Azure Functions using TypeScript. This guide covers MCP tools, resources, l...

3 days ago

Setting up Power BI Version Control with Azure Dev Ops

In this blog post is a way set up version control for Power BI semantic models (and reports) using the PBIP (Power BI Project) format, Azure D...

8 days ago

Azure Developer CLI (azd) – March 2026: Run and Debug AI Agents Locally, GitHub Copilot Integration, & Container App Jobs

Run, invoke, and monitor AI agents locally or in Microsoft Foundry with the new azd AI agent extension commands. Plus GitHub Copilot-powered p...

9 days ago

Writing Azure service-related unit tests with Docker using Spring Cloud Azure

This post shows how to write Azure service-related unit tests with Docker using Spring Cloud Azure. The post Writing Azure service-related uni...

10 days ago

Azure SDK Release (March 2026)

Azure SDK releases every month. In this post, you find this month's highlights and release notes. The post Azure SDK Release (March 2026) appe...

13 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy