Public/Deploy/IaaS/wvd/New-CmAzWVDEnvironment.json

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "Environments": {
            "type": "Array"
        },
        "LogAnalyticsLinkName": {
            "type": "String",
            "defaultValue": "none"
        },
        "LogAnalyticsID": {
            "type": "String",
            "defaultValue": "none"
        }
    },
    "functions": [],
    "variables": {
        "logAnalyticsRetentionPolicy": {
            "enabled": true,
            "days": 30
        }
    },
    "resources": [
        {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2019-10-01",
            "name": "[parameters('Environments')[copyIndex('ResourceGroupCopy')].resourceGroupName]",
            "location": "[parameters('Environments')[copyIndex('ResourceGroupCopy')].wvdEnvironmentLocation]",
            "copy": {
                "name": "ResourceGroupCopy",
                "count": "[length(parameters('Environments'))]"
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2019-10-01",
            "dependsOn": ["[resourceId('Microsoft.Resources/resourceGroups', parameters('Environments')[copyIndex('WVDEnvironmentCopy')].resourceGroupName)]"],
            "name": "[concat('WVDhostpool-Setup_', parameters('Environments')[copyIndex('WVDEnvironmentCopy')].workspaceName)]",
            "resourceGroup": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].resourceGroupName]",
            "properties": {
                "expressionEvaluationOptions": {
                    "scope": "outer"
                },
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "type": "Microsoft.DesktopVirtualization/hostPools",
                            "apiVersion": "2019-12-10-preview",
                            "name": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolName]",
                            "location": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].wvdEnvironmentLocation]",
                            "properties": {
                                "description": "Host Pool created through Cloudmarque.",
                                "friendlyName": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolFriendlyName]",
                                "hostPoolType": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolType]",
                                "maxSessionLimit": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolMaxSessions]",
                                "loadBalancerType": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolBalancing]",
                                "personalDesktopAssignmentType": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.personalDesktopAssignmentType]",
                                "vmTemplate": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostVm.vmTemplateString]"
                            }
                        },
                        {
                            "dependsOn": ["[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolName]"],
                            "condition": "[not(equals(parameters('LogAnalyticsID'), 'none'))]",
                            "type": "Microsoft.DesktopVirtualization/hostPools/Providers/DiagnosticSettings",
                            "apiVersion": "2017-05-01-preview",
                            "name": "[concat(parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolName, '/Microsoft.Insights/', parameters('LogAnalyticsLinkName'))]",
                            "location": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].wvdEnvironmentLocation]",
                            "properties": {
                                "workspaceId": "[if(equals(parameters('LogAnalyticsID'), 'none'), json('null'), parameters('LogAnalyticsID'))]",
                                "logs": [
                                    {
                                        "category": "Checkpoint",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Error",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Management",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Connection",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "HostRegistration",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    }
                                ]
                            }
                        },
                        {
                            "dependsOn": ["[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolName]"],
                            "type": "Microsoft.DesktopVirtualization/applicationgroups",
                            "apiVersion": "2019-12-10-preview",
                            "name": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].desktopGroupName]",
                            "location": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].wvdEnvironmentLocation]",
                            "kind": "Desktop",
                            "properties": {
                                "description": "Desktop Application Group created through Cloudmarque.",
                                "friendlyName": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolFriendlyName]",
                                "hostPoolArmPath": "[concat(subscription().id, '/resourcegroups/', parameters('Environments')[copyIndex('WVDEnvironmentCopy')].resourceGroupName, '/providers/', 'Microsoft.DesktopVirtualization/hostPools/', parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostpool.hostpoolName)]",
                                "applicationGroupType": "Desktop"
                            }
                        },
                        {
                            "dependsOn": ["[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].desktopGroupName]"],
                            "condition": "[not(equals(parameters('LogAnalyticsID'), 'none'))]",
                            "type": "Microsoft.DesktopVirtualization/applicationgroups/Providers/DiagnosticSettings",
                            "apiVersion": "2017-05-01-preview",
                            "name": "[concat(parameters('Environments')[copyIndex('WVDEnvironmentCopy')].desktopGroupName, '/Microsoft.Insights/', parameters('LogAnalyticsLinkName'))]",
                            "location": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].wvdEnvironmentLocation]",
                            "properties": {
                                "workspaceId": "[if(equals(parameters('LogAnalyticsID'), 'none'), json('null'), parameters('LogAnalyticsID'))]",
                                "logs": [
 
                                    {
                                        "category": "Checkpoint",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Error",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Management",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    }
                                ]
                            }
                        },
                        {
                            "dependsOn": ["[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].desktopGroupName]"],
                            "type": "Microsoft.DesktopVirtualization/workspaces",
                            "apiVersion": "2019-12-10-preview",
                            "name": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].workspaceName]",
                            "location": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].wvdEnvironmentLocation]",
                            "properties": {
                                "friendlyName": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].workspaceFriendlyName]",
                                "description": "Workspace created through Cloudmarque",
                                "applicationGroupReferences": ["[concat(subscription().id, '/resourcegroups/', parameters('Environments')[copyIndex('WVDEnvironmentCopy')].resourceGroupName, '/providers/Microsoft.DesktopVirtualization/applicationgroups/', parameters('Environments')[copyIndex('WVDEnvironmentCopy')].desktopGroupName)]"]
                            }
                        },
                        {
                            "dependsOn": ["[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].workspaceName]"],
                            "condition": "[not(equals(parameters('LogAnalyticsID'), 'none'))]",
                            "type": "Microsoft.DesktopVirtualization/workspaces/Providers/DiagnosticSettings",
                            "apiVersion": "2017-05-01-preview",
                            "name": "[concat(parameters('Environments')[copyIndex('WVDEnvironmentCopy')].workspaceName, '/Microsoft.Insights/', parameters('LogAnalyticsLinkName'))]",
                            "location": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].wvdEnvironmentLocation]",
                            "properties": {
                                "workspaceId": "[if(equals(parameters('LogAnalyticsID'), 'none'), json('null'), parameters('LogAnalyticsID'))]",
                                "logs": [
 
                                    {
                                        "category": "Checkpoint",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Error",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Management",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    },
                                    {
                                        "category": "Feed",
                                        "enabled": true,
                                        "retentionPolicy": "[variables('logAnalyticsRetentionPolicy')]"
                                    }
                                ]
                            }
                        },
                        {
                            "type": "Microsoft.Compute/availabilitySets",
                            "name": "[concat(parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostVm.hostVmNamePrefix,'-availabilitySet-', replace(parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostVm.hostVmLocation,' ',''))]",
                            "apiVersion": "2019-07-01",
                            "location": "[parameters('Environments')[copyIndex('WVDEnvironmentCopy')].hostVm.hostVmLocation]",
                            "properties": {
                                "platformFaultDomainCount": 2,
                                "platformUpdateDomainCount": 5
                            },
                            "sku": {
                                // Sku of the availability set, only name is required to be set. See AvailabilitySetSkuTypes for possible set of values. Use 'Aligned' for virtual machines with managed disks and 'Classic' for virtual machines with unmanaged disks. Default value is 'Classic'.
                                "name": "Aligned"
                            }
                        }
                    ]
                }
            },
            "copy": {
                "name": "WVDEnvironmentCopy",
                "count": "[length(parameters('Environments'))]"
            }
        }
    ],
    "outputs": {}
}