Bylaw

Gallery › Compute › Azure built-in policies

Allowed virtual machine size SKUs

Converted Policy Deny Mode Indexed Version 1.0.1

This policy enables you to specify a set of virtual machine size SKUs that your organization can deploy.

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

Azure Policy JSONVMSkusAllowed_Deny.json · 47 lines
{
  "properties": {
    "displayName": "Allowed virtual machine size SKUs",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy enables you to specify a set of virtual machine size SKUs that your organization can deploy.",
    "metadata": {
      "version": "1.0.1",
      "category": "Compute"
    },
    "version": "1.0.1",
    "parameters": {
      "listOfAllowedSKUs": {
        "type": "Array",
        "metadata": {
          "description": "The list of size SKUs that can be specified for virtual machines.",
          "displayName": "Allowed Size SKUs",
          "strongType": "VMSKUs"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines"
          },
          {
            "not": {
              "field": "Microsoft.Compute/virtualMachines/sku.name",
              "in": "[parameters('listOfAllowedSKUs')]"
            }
          }
        ]
      },
      "then": {
        "effect": "Deny"
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/cccc23c7-8427-4f53-ad12-b6a63eb452b3",
  "name": "cccc23c7-8427-4f53-ad12-b6a63eb452b3"
}
Bylawcccc23c7-8427-4f53-ad12-b6a63eb452b3.bylaw.ps1 · 28 lines
# Converted from VMSkusAllowed_Deny.json by ConvertTo-Bylaw.
Policy 'cccc23c7-8427-4f53-ad12-b6a63eb452b3' {

    Properties @{
        DisplayName   = 'Allowed virtual machine size SKUs'
        Description   = 'This policy enables you to specify a set of virtual machine size SKUs that your organization can deploy.'
        Version       = '1.0.1'
        Category      = 'Compute'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

    Parameter ListOfAllowedSKUs @{
        Type        = 'Array'
        DisplayName = 'Allowed Size SKUs'
        Description = 'The list of size SKUs that can be specified for virtual machines.'
        Metadata    = [ordered]@{ strongType = 'VMSKUs' }
    }

    Resource 'Microsoft.Compute/virtualMachines' {

        Require 'sku.name is one of the ListOfAllowedSKUs parameter' {
            Field sku.name | Must -BeIn (Param ListOfAllowedSKUs)
        }
    }

    Effect Deny
}

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