{
   "if": {
      "field": "type",
      "equals": "Microsoft.Compute/virtualMachineScaleSets"
   },
   "then": {
      "effect": "deployIfNotExists",
      "details": {
         "type": "Microsoft.Compute/virtualMachineScaleSets",
         "name": "[field('name')]",
         "existenceCondition": {
            "field": "Microsoft.Compute/VirtualMachineScaleSets/upgradePolicy.automaticOSUpgrade",
            "equals": "true"
         },
         "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"
         ],
         "deployment": {
            "properties": {
               "mode": "incremental",
               "template": {
                  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                  "contentVersion": "1.0.0.0",
                  "parameters": {
                     "vmssName": {
                        "type": "string"
                     },
                     "location": {
                        "type": "string"
                     }
                  },
                  "resources": [
                     {
                        "name": "[parameters('vmssName')]",
                        "type": "Microsoft.Compute/virtualMachineScaleSets",
                        "location": "[parameters('location')]",
                        "apiVersion": "2018-10-01",
                        "properties": {
                           "upgradePolicy": {
                              "automaticOSUpgradePolicy": {
                                 "enableAutomaticOSUpgrade": true
                              }
                           }
                        }
                     }
                  ]
               },
               "parameters": {
                  "vmssName": {
                     "value": "[field('name')]"
                  },
                  "location": {
                     "value": "[field('location')]"
                  }
               }
            }
         }
      }
   }
}