Bylaw

Gallery › Compute › Azure Community Policy

Audit Virtual Machine Scale Sets without automatic OS upgrade enabled

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

This policy audits any Virtual Machine Scale Set that does not have automatic OS upgrade enabled.

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

Azure Policy JSONazurepolicy.json · 44 lines
{
  "name": "4bebdb08-30b3-42c9-b247-e96f50515502",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit Virtual Machine Scale Sets without automatic OS upgrade enabled",
    "description": "This policy audits any Virtual Machine Scale Set that does not have automatic OS upgrade enabled.",
    "metadata": {
      "category": "Compute",
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachineScaleSets"
          },
          {
            "field": "Microsoft.Compute/VirtualMachineScaleSets/upgradePolicy.automaticOSUpgrade",
            "notEquals": "true"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw4bebdb08-30b3-42c9-b247-e96f50515502.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '4bebdb08-30b3-42c9-b247-e96f50515502' {

    Properties @{
        DisplayName = 'Audit Virtual Machine Scale Sets without automatic OS upgrade enabled'
        Description = 'This policy audits any Virtual Machine Scale Set that does not have automatic OS upgrade enabled.'
        Category    = 'Compute'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

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

    Resource 'Microsoft.Compute/virtualMachineScaleSets' {

        Require 'upgradePolicy.automaticOSUpgrade is true' {
            Field upgradePolicy.automaticOSUpgrade | Must -Be 'true'
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Compute/audit-virtual-machine-scale-sets-without-automatic-os-upgrade-enabled/azurepolicy.json in Azure/Community-Policy, under the MIT licence.