{
    "if": {
        "allOf": [
            {
                "field": "type",
                "equals": "Microsoft.Compute/virtualMachines"
            },
            {
                "anyOf": [
                    {
                        "field": "Microsoft.Compute/imagePublisher",
                        "in": [
                            "microsoft-aks",
                            "AzureDatabricks",
                            "qubole-inc",
                            "datastax",
                            "couchbase",
                            "scalegrid",
                            "checkpoint",
                            "paloaltonetworks"
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "OpenLogic"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "like": "CentOS*"
                            },
                            {
                                "field": "Microsoft.Compute/imageSKU",
                                "notLike": "6*"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "RedHat"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "equals": "RHEL"
                            },
                            {
                                "field": "Microsoft.Compute/imageSKU",
                                "notLike": "6*"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "RedHat"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "equals": "osa"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "credativ"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "equals": "Debian"
                            },
                            {
                                "field": "Microsoft.Compute/imageSKU",
                                "notLike": "7*"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "Suse"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "like": "SLES*"
                            },
                            {
                                "field": "Microsoft.Compute/imageSKU",
                                "notLike": "11*"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "Canonical"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "equals": "UbuntuServer"
                            },
                            {
                                "field": "Microsoft.Compute/imageSKU",
                                "notLike": "12*"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "microsoft-dsvm"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "in": [
                                    "linux-data-science-vm-ubuntu",
                                    "azureml"
                                ]
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "cloudera"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "equals": "cloudera-centos-os"
                            },
                            {
                                "field": "Microsoft.Compute/imageSKU",
                                "notLike": "6*"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "cloudera"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "equals": "cloudera-altus-centos-os"
                            }
                        ]
                    },
                    {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/imagePublisher",
                                "equals": "microsoft-ads"
                            },
                            {
                                "field": "Microsoft.Compute/imageOffer",
                                "like": "linux*"
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "then": {
        "effect": "deployIfNotExists",
        "details": {
            "type": "Microsoft.GuestConfiguration/guestConfigurationAssignments",
            "name": "installed_application_linux",
            "roleDefinitionIds": [
                "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
            ],
            "deployment": {
                "properties": {
                    "mode": "incremental",
                    "parameters": {
                        "vmName": {
                            "value": "[field('name')]"
                        },
                        "location": {
                            "value": "[field('location')]"
                        },
                        "configurationName": {
                            "value": "installed_application_linux"
                        },
                        "ApplicationName": {
                            "value": "[parameters('ApplicationName')]"
                        }
                    },
                    "template": {
                        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "parameters": {
                            "vmName": {
                                "type": "string"
                            },
                            "location": {
                                "type": "string"
                            },
                            "configurationName": {
                                "type": "string"
                            },
                            "ApplicationName": {
                                "type": "string"
                            }
                        },
                        "resources": [
                            {
                                "apiVersion": "2018-11-20",
                                "type": "Microsoft.Compute/virtualMachines/providers/guestConfigurationAssignments",
                                "name": "[concat(parameters('vmName'), '/Microsoft.GuestConfiguration/', parameters('configurationName'))]",
                                "location": "[parameters('location')]",
                                "properties": {
                                    "guestConfiguration": {
                                        "name": "[parameters('configurationName')]",
                                        "version": "1.*",
                                        "configurationParameter": [
                                            {
                                                "name": "[ChefInSpec]InstalledApplicationLinuxResource1;AttributesYmlContent",
                                                "value": "[concat('packages: [', parameters('ApplicationName'), ']')]"
                                            }
                                        ]
                                    }
                                }
                            },
                            {
                                "apiVersion": "2017-03-30",
                                "type": "Microsoft.Compute/virtualMachines",
                                "identity": {
                                    "type": "SystemAssigned"
                                },
                                "name": "[parameters('vmName')]",
                                "location": "[parameters('location')]"
                            },
                            {
                                "apiVersion": "2015-05-01-preview",
                                "name": "[concat(parameters('vmName'), '/AzurePolicyforLinux')]",
                                "type": "Microsoft.Compute/virtualMachines/extensions",
                                "location": "[parameters('location')]",
                                "properties": {
                                    "publisher": "Microsoft.GuestConfiguration",
                                    "type": "ConfigurationforLinux",
                                    "typeHandlerVersion": "1.0",
                                    "autoUpgradeMinorVersion": true
                                },
                                "dependsOn": [
                                    "[concat('Microsoft.Compute/virtualMachines/',parameters('vmName'),'/providers/Microsoft.GuestConfiguration/guestConfigurationAssignments/',parameters('configurationName'))]"
                                ]
                            }
                        ]
                    }
                }
            }
        }
    }
}