Gallery › Security Center › Azure built-in policies
Configure Microsoft Defender for Servers plan (P1 OR P2)
Converted Policy DeployIfNotExists Disabled Mode All Version 1.1.0
Ensures that the selected Microsoft Defender for Servers subplan (P1 or P2) is enabled at the subscription level. This policy supports dynamic selection via parameters and enforces deployment if not already configured.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONASC_Azure_Defender_Servers_PlanP1P2_ParamBased_DINE.json · 111 lines
{
"properties": {
"displayName": "Configure Microsoft Defender for Servers plan (P1 OR P2)",
"policyType": "BuiltIn",
"mode": "All",
"description": "Ensures that the selected Microsoft Defender for Servers subplan (P1 or P2) is enabled at the subscription level. This policy supports dynamic selection via parameters and enforces deployment if not already configured.",
"metadata": {
"version": "1.1.0",
"category": "Security Center"
},
"version": "1.1.0",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
},
"subPlan": {
"type": "String",
"metadata": {
"displayName": "Defender for Servers plans",
"description": "Select a Defender for Servers plan"
},
"allowedValues": [
"P1",
"P2"
],
"defaultValue": "P2"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Resources/subscriptions"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Security/pricings",
"name": "VirtualMachines",
"deploymentScope": "subscription",
"existenceScope": "subscription",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"
],
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Security/pricings/pricingTier",
"equals": "Standard"
},
{
"field": "Microsoft.Security/pricings/subPlan",
"equals": "[parameters('subPlan')]"
},
{
"field": "Microsoft.Security/pricings/enforce",
"equals": "True"
}
]
},
"deployment": {
"location": "eastus",
"properties": {
"mode": "incremental",
"parameters": {
"subPlan": {
"value": "[parameters('subPlan')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subPlan": {
"type": "String"
}
},
"resources": [
{
"type": "Microsoft.Security/pricings",
"apiVersion": "2024-01-01",
"name": "VirtualMachines",
"properties": {
"pricingTier": "Standard",
"subPlan": "[parameters('subPlan')]",
"enforce": "True"
}
}
]
}
}
}
}
}
},
"versions": [
"1.1.0",
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/5f57b753-04b4-4e5e-aa31-c8888984497a",
"name": "5f57b753-04b4-4e5e-aa31-c8888984497a"
}Bylaw5f57b753-04b4-4e5e-aa31-c8888984497a.bylaw.ps1 · 43 lines
# Converted from ASC_Azure_Defender_Servers_PlanP1P2_ParamBased_DINE.json by ConvertTo-Bylaw.
Policy '5f57b753-04b4-4e5e-aa31-c8888984497a' {
Properties @{
DisplayName = 'Configure Microsoft Defender for Servers plan (P1 OR P2)'
Description = 'Ensures that the selected Microsoft Defender for Servers subplan (P1 or P2) is enabled at the subscription level. This policy supports dynamic selection via parameters and enforces deployment if not already configured.'
Version = '1.1.0'
Category = 'Security Center'
PolicyVersion = '1.1.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter SubPlan @{
AllowedValues = @('P1', 'P2')
Default = 'P2'
DisplayName = 'Defender for Servers plans'
Description = 'Select a Defender for Servers plan'
}
Resource 'Microsoft.Resources/subscriptions'
DeployIfNotExists 'Microsoft.Security/pricings' -Role 'Owner' -Name 'VirtualMachines' -ExistenceScope Subscription -Effect (Param Effect) {
Require 'pricingTier is Standard, subPlan is the SubPlan parameter and enforce is True' {
Field pricingTier | Must -Be 'Standard'
Field subPlan | Must -Be (Param SubPlan)
Field enforce | Must -Be 'True'
}
Deployment @{
TemplateFile = './templates/5f57b753-04b4-4e5e-aa31-c8888984497a.json'
Scope = 'Subscription'
Location = 'eastus'
Parameters = [ordered]@{
subPlan = (Param SubPlan)
}
}
}
}Its deployment templates are written beside it:
templates/5f57b753-04b4-4e5e-aa31-c8888984497a.json
Source: built-in-policies/policyDefinitions/Security Center/ASC_Azure_Defender_Servers_PlanP1P2_ParamBased_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw