Bylaw

Gallery › Compute › Azure Community Policy

audit-vms-based-on-marketplace-acg-images

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Audit Virtual Machines based on marketplace or Azure Compute Gallery images. createOption value 'FromImage' is used when you are using an image to create the virtual machine.

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

Azure Policy JSONazurepolicy.json · 45 lines
{
  "name": "f858ee3e-c148-4be0-9286-62b66d581c76",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "audit-vms-based-on-marketplace-acg-images",
    "description": "Audit Virtual Machines based on marketplace or Azure Compute Gallery images. createOption value 'FromImage' is used when you are using an image to create the virtual machine.",
    "metadata": {
      "category": "Compute",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "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"
          },
          {
            "field": "Microsoft.Compute/virtualMachines/storageProfile.osDisk.createOption",
            "equals": "FromImage"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawf858ee3e-c148-4be0-9286-62b66d581c76.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'f858ee3e-c148-4be0-9286-62b66d581c76' {

    Properties @{
        DisplayName = 'audit-vms-based-on-marketplace-acg-images'
        Description = 'Audit Virtual Machines based on marketplace or Azure Compute Gallery images. createOption value ''FromImage'' is used when you are using an image to create the virtual machine.'
        Category    = 'Compute'
        Version     = '1.0.0'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.Compute/virtualMachines' {

        Require 'storageProfile.osDisk.createOption is not FromImage' {
            Field storageProfile.osDisk.createOption | Must -Not -Be 'FromImage' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Compute/audit-vms-based-on-marketplace-acg-images/azurepolicy.json in Azure/Community-Policy, under the MIT licence.