What is Azure Policy?

Azure Policy helps you enforce organizational standards and assess compliance at scale. It allows you to ensure that Azure resources you deploy conform to your company's requirements. Azure Policy is a service that helps you implement and adhere to your organization's governance standards for Azure resources.

With Azure Policy, you can:

Key Concepts

Understanding the core components of Azure Policy is crucial for effective governance:

  • Policy Definition: A rule or set of rules that defines what constitutes a compliant or non-compliant resource.
  • Policy Assignment: The act of applying a policy definition to a specific scope (e.g., subscription, resource group).
  • Policy Initiative (Set): A collection of related policy definitions grouped together to achieve a broader governance objective.
  • Effect: The action to take when a policy rule is matched (e.g., Deny, Audit, Append, Modify, DeployIfNotExists).
  • Resource Provider: The service responsible for managing Azure resources (e.g., Microsoft.Compute, Microsoft.Storage).

How Azure Policy Works

Azure Policy evaluates resources by comparing resource properties to the conditions defined in a policy rule. When a resource is created or updated, or when a policy assignment is made, Azure Policy evaluates the resource. If a resource violates a policy rule, the configured effect is enforced.

Common Effects:

Example Policy Definition (JSON):

This example policy audits virtual machines that do not have the "monitoring" tag assigned.


{
  "mode": "Indexed",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Compute/virtualMachines"
        },
        {
          "field": "tags.monitoring",
          "exists": "false"
        }
      ]
    },
    "then": {
      "effect": "audit"
    }
  },
  "parameters": {}
}
            

Getting Started with Azure Policy

You can manage Azure Policy through the Azure portal, Azure CLI, Azure PowerShell, or REST API.

Using the Azure Portal:

  1. Navigate to the Azure portal and search for "Policy".
  2. Under "Authoring", select "Definitions" to view built-in policies or create custom ones.
  3. Under "Authoring", select "Assignments" to apply policies to subscriptions or resource groups.
  4. Under "Compliance", review your compliance dashboard.

Key Scenarios: