Azure custom policy for installing extension "AADLoginForWindows"

Viewed 44

I'm trying to create Azure custom policy to install extension "AADLoginForWindows" to be enabled on all existing and newly created VMs. When im creating the custom policy definition getting below error message.

Custom policy:

{ "properties": { "policyType": "custom", "displayName": "Install aadloginforwindows extension on Windows 2019 server and Windows 10 VMs", "mode": "all", "description": "Install aadloginforwindows extension on Windows 2019 server and Windows 10 VMs for Azure active directory login",

"parameters": {
  "listOfImageIdToInclude": {
    "type": "Array",
    "metadata": {
      "displayName": "Optional: List of virtual machine images that have supported Windows OS to add to scope",
      "description": "Windows Server 2019 and Windows10 is supported"
    },
    "defaultValue": []
  },
  "effect": {
    "type": "String",
    "metadata": {
      "displayName": "Effect",
      "description": "Enable or disable the execution of the policy"
    },
    "allowedValues": [
      "DeployIfNotExists",
      "Disabled"
    ],
    "defaultValue": "DeployIfNotExists"
  },
  

"policyRule": {
  "if": {
    "allOf": [
      {
        "field": "type",
        "equals": "Microsoft.Compute/virtualMachines"
      },
      
      {
        "anyOf": [
          {
            "field": "Microsoft.Compute/imageId",
            "in": "[parameters('listOfImageIdToInclude')]"
          },
          {
            "allOf": [
              {
                "field": "Microsoft.Compute/imagePublisher",
                "equals": "MicrosoftWindowsServer"
              },
              {
                "field": "Microsoft.Compute/imageOffer",
                "equals": "WindowsServer"
              },
              {
                "field": "Microsoft.Compute/imageSKU",
                "in": [
                  "2019-Datacenter",
                  "2019-Datacenter-smalldisk",
                  "2019-Datacenter-with-Containers",
                  "2019-Datacenter-with-Containers-smalldisk",
                  "2019-Datacenter-zhcn",
                  "2019-datacenter-gensecond"
                ]
              }
            ]
          },{
                                            "allOf": [
              {
                "field": "Microsoft.Compute/imagePublisher",
                "equals": "MicrosoftWindowsDesktop"
              },
              {
                "field": "Microsoft.Compute/imageOffer",
                "equals": "Windows-10"
              }
            ]
          }
        ]
      }
    ]
  },
  "then": {
    "effect": "[parameters('effect')]",
    "details": {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "roleDefinitionIds": [
        "/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
      ],
      "existenceCondition": {
        "allOf": [
          {
            "field": "Microsoft.Compute/virtualMachines/extensions/type",
            "equals": "AADLoginForWindows"
          },
          
          {
            "field": "Microsoft.Compute/virtualMachines/extensions/provisioningState",
            "equals": "Succeeded"
          }
        ]
      },
      "deployment": {
        "properties": {
          "mode": "incremental",
          "template": {
            "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {
              "vmName": {
                "type": "string"
              },
              "location": {
                "type": "string"
              }
            },
            "variables": {
              "vmExtensionName": "AADLoginForWindows",
              "vmExtensionPublisher": "Microsoft.Azure.ActiveDirectory",
              "vmExtensionType": "AADLoginForWindows",
              "vmExtensionTypeHandlerVersion": "1.0"
            },
            "resources": [
              {
                "type": "Microsoft.Compute/virtualMachines/extensions",
                "name": "[concat(parameters('vmName'), '/', variables('vmExtensionName'))]",
                "apiVersion": "2021-04-01",
                "location": "[parameters('location')]",
                "properties": {
                  "publisher": "[variables('vmExtensionPublisher')]",
                  "type": "[variables('vmExtensionType')]",
                  "typeHandlerVersion": "[variables('vmExtensionTypeHandlerVersion')]",
                  "autoUpgradeMinorVersion": true
                  
                }
              }
            ],
            "outputs": {
              "policy": {
                "type": "string",
                "value": "[concat('Enabled extension for VM', ': ', parameters('vmName'))]"
              }
            }
          },
          "parameters": {
            "vmName": {
              "value": "[field('name')]"
            },
            "location": {
              "value": "[field('location')]"
            }
          }
        }
      }
    }
  }
}

}

}}


Error message: The request content was invalid and could not be deserialized: 'Required property 'type' not found in JSON. Path 'properties.parameters.policyRule', line 1, position 571.'.

Any inputs/feedback will be helpful. Couldnt find any policy sample or built in policy for this extension.

0 Answers
Related