Bylaw

Gallery › Automanage › Azure built-in policies

Hotpatch should be enabled for Windows Server Azure Edition VMs

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Minimize reboots and install updates quickly with hotpatch. Learn more at https://docs.microsoft.com/azure/automanage/automanage-hotpatch

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONHotpatchShouldBeEnabledforWindowsServerAzureEditionVMs.json · 61 lines
{
  "properties": {
    "displayName": "Hotpatch should be enabled for Windows Server Azure Edition VMs",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Minimize reboots and install updates quickly with hotpatch. Learn more at https://docs.microsoft.com/azure/automanage/automanage-hotpatch",
    "metadata": {
      "version": "1.0.0",
      "category": "Automanage"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines"
          },
          {
            "field": "Microsoft.Compute/virtualMachines/storageProfile.imageReference.sku",
            "in": [
              "2022-datacenter-azure-edition",
              "2022-datacenter-azure-edition-core",
              "2022-datacenter-azure-edition-core-smalldisk",
              "2022-datacenter-azure-edition-smalldisk"
            ]
          },
          {
            "not": {
              "field": "Microsoft.Compute/virtualMachines/osProfile.windowsConfiguration.patchSettings.enableHotpatching",
              "equals": "true"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/6d02d2f7-e38b-4bdc-96f3-adc0a8726abc",
  "name": "6d02d2f7-e38b-4bdc-96f3-adc0a8726abc"
}
Bylaw6d02d2f7-e38b-4bdc-96f3-adc0a8726abc.bylaw.ps1 · 32 lines
# Converted from HotpatchShouldBeEnabledforWindowsServerAzureEditionVMs.json by ConvertTo-Bylaw.
Policy '6d02d2f7-e38b-4bdc-96f3-adc0a8726abc' {

    Properties @{
        DisplayName   = 'Hotpatch should be enabled for Windows Server Azure Edition VMs'
        Description   = 'Minimize reboots and install updates quickly with hotpatch. Learn more at https://docs.microsoft.com/azure/automanage/automanage-hotpatch'
        Version       = '1.0.0'
        Category      = 'Automanage'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Compute/virtualMachines' {

        When {
            Field storageProfile.imageReference.sku | Must -BeIn @('2022-datacenter-azure-edition', '2022-datacenter-azure-edition-core', '2022-datacenter-azure-edition-core-smalldisk', '2022-datacenter-azure-edition-smalldisk')
        }

        Require 'osProfile.windowsConfiguration.patchSettings.enableHotpatching is true' {
            Field osProfile.windowsConfiguration.patchSettings.enableHotpatching | Must -Be 'true'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Automanage/HotpatchShouldBeEnabledforWindowsServerAzureEditionVMs.json in Azure/azure-policy, under the MIT licence.