Bylaw

Gallery › Network › Azure Community Policy

Allowed VM Images for Resource Groups containing a specific Suffix

Doesn't convert yet Policy Audit Deny Disabled Mode All Version 1.0.0

This Policy will prevent VM images not listed by this Policy from being deployed to Resource Groups containing a suffix that you define here.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 82 lines
{
  "name": "951246be-2017-49c2-8a92-a5a0cc19f8b0",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Allowed VM Images for Resource Groups containing a specific Suffix",
    "description": "This Policy will prevent VM images not listed by this Policy from being deployed to Resource Groups containing a suffix that you define here.",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "mode": "All",
    "parameters": {
      "resourceGroupSuffix": {
        "type": "String",
        "metadata": {
          "displayName": "Resource Group Suffix",
          "description": "Resource Groups containing this suffix will be permitted to deploy only the VM images definied in other parts of this Policy."
        }
      },
      "allowedImagePublishers": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Image Publishers",
          "description": "Publishers listed here are the only ones approved to be deployed to the target Resource Group. More granularity can be achieved with the Offers parameter below. Use this command to get a list of Publishers: Get-AzVMImagePublisher -Location ''"
        },
        "defaultValue": "NA"
      },
      "allowedImageOffers": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Image Offers",
          "description": "Offers listed here are the only ones approved to be deployed to the target Resource Group. If you want less granularity use the Publishers parameter. Use this command to get a list of Offers: Get-AzVMImageOffer -Location '' -PublisherName ''"
        },
        "defaultValue": "NA"
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines"
          },
          {
            "not": {
              "anyOf": [
                {
                  "field": "Microsoft.Compute/virtualMachines/imagePublisher",
                  "in": "[parameters('allowedImagePublishers')]"
                },
                {
                  "field": "Microsoft.Compute/virtualMachines/imageOffer",
                  "in": "[parameters('allowedImageOffers')]"
                }
              ]
            }
          },
          {
            "value": "[resourceGroup().name]",
            "like": "[concat('*', parameters('resourceGroupSuffix'))]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}

Source: policyDefinitions/Network/allowed-vm-images-for-resource-groups-containing-a-specific-suffix/azurepolicy.json in Azure/Community-Policy, under the MIT licence.