{
    "properties": {
        "displayName": "Dependency agent should be enabled in virtual machine scale sets for listed virtual machine images",
        "policyType": "BuiltIn",
        "mode": "Indexed",
        "description": "Reports virtual machine scale sets as non-compliant if the virtual machine image is not in the list defined and the agent is not installed. The list of OS images is updated over time as support is updated.",
        "metadata": {
            "version": "2.0.0",
            "category": "Monitoring"
        },
        "parameters": {
            "listOfImageIdToInclude_windows": {
                "type": "Array",
                "defaultValue": [],
                "metadata": {
                    "displayName": "Optional: List of virtual machine images that have supported Windows OS to add to scope",
                    "description": "Example value: '/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'"
                }
            },
            "listOfImageIdToInclude_linux": {
                "type": "Array",
                "defaultValue": [],
                "metadata": {
                    "displayName": "Optional: List of virtual machine images that have supported Linux OS to add to scope",
                    "description": "Example value: '/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'"
                }
            },
            "effect": {
                "type": "string",
                "defaultValue": "AuditIfNotExists",
                "allowedValues": [
                  "AuditIfNotExists",
                  "Disabled"
                ],
                "metadata": {
                  "displayName": "Effect",
                  "description": "Enable or disable the execution of the policy"
                }
            }
        },
        "policyRule": {
            "if": {
                "allOf": [
                    {
                        "field": "type",
                        "equals": "Microsoft.Compute/virtualMachineScaleSets"
                    },
                    {
                        "not": {
                            "anyOf": [
                                {
                                    "field": "Microsoft.Compute/imageId",
                                    "in": "[parameters('listOfImageIdToInclude_windows')]"
                                },
                                {
                                    "field": "Microsoft.Compute/imageId",
                                    "in": "[parameters('listOfImageIdToInclude_linux')]"
                                },
                                {
                                    "anyOf": [
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftWindowsServer"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "WindowsServer"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "in": [
                                                        "2008-R2-SP1",
                                                        "2008-R2-SP1-smalldisk",
                                                        "2012-Datacenter",
                                                        "2012-Datacenter-smalldisk",
                                                        "2012-R2-Datacenter",
                                                        "2012-R2-Datacenter-smalldisk",
                                                        "2016-Datacenter",
                                                        "2016-Datacenter-Server-Core",
                                                        "2016-Datacenter-Server-Core-smalldisk",
                                                        "2016-Datacenter-smalldisk",
                                                        "2016-Datacenter-with-Containers",
                                                        "2016-Datacenter-with-RDSH",
                                                        "2019-Datacenter",
                                                        "2019-Datacenter-Core",
                                                        "2019-Datacenter-Core-smalldisk",
                                                        "2019-Datacenter-Core-with-Containers",
                                                        "2019-Datacenter-Core-with-Containers-smalldisk",
                                                        "2019-Datacenter-smalldisk",
                                                        "2019-Datacenter-with-Containers",
                                                        "2019-Datacenter-with-Containers-smalldisk",
                                                        "2019-Datacenter-zhcn"
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftWindowsServer"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "WindowsServerSemiAnnual"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "in": [
                                                        "Datacenter-Core-1709-smalldisk",
                                                        "Datacenter-Core-1709-with-Containers-smalldisk",
                                                        "Datacenter-Core-1803-with-Containers-smalldisk"
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftWindowsServerHPCPack"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "WindowsServerHPCPack"
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftSQLServer"
                                                },
                                                {
                                                    "anyOf": [
                                                        {
                                                            "field": "Microsoft.Compute/imageOffer",
                                                            "like": "*-WS2016"
                                                        },
                                                        {
                                                            "field": "Microsoft.Compute/imageOffer",
                                                            "like": "*-WS2016-BYOL"
                                                        },
                                                        {
                                                            "field": "Microsoft.Compute/imageOffer",
                                                            "like": "*-WS2012R2"
                                                        },
                                                        {
                                                            "field": "Microsoft.Compute/imageOffer",
                                                            "like": "*-WS2012R2-BYOL"
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftRServer"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "MLServer-WS2016"
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftVisualStudio"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "in": [
                                                        "VisualStudio",
                                                        "Windows"
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftDynamicsAX"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "Dynamics"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "equals": "Pre-Req-AX7-Onebox-U8"
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftDynamicsAX"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "Dynamics"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "equals": "Pre-Req-AX7-Onebox-V4"
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "microsoft-ads"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "windows-data-science-vm"
                                                }
                                            ]
                                        },
                                        {
                                            "allOf": [
                                                {
                                                    "field": "Microsoft.Compute/imagePublisher",
                                                    "equals": "MicrosoftWindowsDesktop"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageOffer",
                                                    "equals": "Windows-10"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "allOf": [
                                        {
                                            "field": "Microsoft.Compute/imagePublisher",
                                            "equals": "RedHat"
                                        },
                                        {
                                            "field": "Microsoft.Compute/imageOffer",
                                            "in": [
                                                "RHEL",
                                                "RHEL-SAP-HANA"
                                            ]
                                        },
                                        {
                                            "anyOf": [
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "like": "6.*"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "like": "7*"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "allOf": [
                                        {
                                            "field": "Microsoft.Compute/imagePublisher",
                                            "equals": "SUSE"
                                        },
                                        {
                                            "field": "Microsoft.Compute/imageOffer",
                                            "in": [
                                                "SLES",
                                                "SLES-HPC",
                                                "SLES-HPC-Priority",
                                                "SLES-SAP",
                                                "SLES-SAP-BYOS",
                                                "SLES-Priority",
                                                "SLES-BYOS",
                                                "SLES-SAPCAL",
                                                "SLES-Standard"
                                            ]
                                        },
                                        {
                                            "anyOf": [
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "in": [
                                                        "12-SP2",
                                                        "12-SP3",
                                                        "12-SP4"
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "allOf": [
                                        {
                                            "field": "Microsoft.Compute/imagePublisher",
                                            "equals": "Canonical"
                                        },
                                        {
                                            "field": "Microsoft.Compute/imageOffer",
                                            "equals": "UbuntuServer"
                                        },
                                        {
                                            "anyOf": [
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "in": [
                                                        "14.04.0-LTS",
                                                        "14.04.1-LTS",
                                                        "14.04.5-LTS"
                                                    ]
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "in": [
                                                        "16.04-LTS",
                                                        "16.04.0-LTS"
                                                    ]
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "in": [
                                                        "18.04-LTS"
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "allOf": [
                                        {
                                            "field": "Microsoft.Compute/imagePublisher",
                                            "equals": "OpenLogic"
                                        },
                                        {
                                            "field": "Microsoft.Compute/imageOffer",
                                            "in": [
                                                "Centos",
                                                "Centos-LVM",
                                                "CentOS-SRIOV"
                                            ]
                                        },
                                        {
                                            "anyOf": [
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "like": "6.*"
                                                },
                                                {
                                                    "field": "Microsoft.Compute/imageSKU",
                                                    "like": "7*"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "allOf": [
                                        {
                                            "field": "Microsoft.Compute/imagePublisher",
                                            "equals": "cloudera"
                                        },
                                        {
                                            "field": "Microsoft.Compute/imageOffer",
                                            "equals": "cloudera-centos-os"
                                        },
                                        {
                                            "field": "Microsoft.Compute/imageSKU",
                                            "like": "7*"
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                ]
            },
            "then": {
                "effect": "[parameters('effect')]",
                "details": {
                    "type": "Microsoft.Compute/virtualMachineScaleSets/extensions",
                    "existenceCondition": {
                        "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/publisher",
                        "equals": "Microsoft.Azure.Monitoring.DependencyAgent"
                    }
                }
            }
        }
    },
    "id": "/providers/Microsoft.Authorization/policyDefinitions/e2dd799a-a932-4e9d-ac17-d473bc3c6c10",
    "name": "e2dd799a-a932-4e9d-ac17-d473bc3c6c10"
}