{
    "type": "Microsoft.Authorization/policyDefinitions",
    "name": "allowed-custom-images", 
    "properties": {
        "displayName": "Approved VM images",
        "description": "This policy governs the approved VM images",
        "parameters": {
            "imageIds": {
                "type": "array",
                "metadata": {
                    "description": "The list of approved VM images. Example values: '/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage' or /Subscriptions/<subscriptionId>/Providers/Microsoft.Compute/Locations/centralus/Publishers/MicrosoftWindowsServer/ArtifactTypes/VMImage/Offers/WindowsServer/Skus/2016-Datacenter/Versions/2016.127.20180510'",
                    "displayName": "Approved VM images"
                }
            }
        },
        "policyRule": {
            "if": {
                "allOf": [
                    {
                        "field": "type",
                        "equals": "Microsoft.Compute/virtualMachines"
                    },
                    {
                        "not": {
                            "field": "Microsoft.Compute/imageId",
                            "in": "[parameters('imageIds')]"
                        }
                    }
                ]
            },
            "then": {
                "effect": "deny"
            }
        }
    }   
}