Template for host pool and application group deployment to existing workspace

Joseph M. Durnal 96 Reputation points
2022-12-09T15:44:20.46+00:00

I'm working on a simple template to quickly deploy host pools and desktop application groups. Not really concerned with adding VMs yet. My trouble is with the workspace. Most of my testing the deployment would just replace the existing application group in the workspace with the newly deployed one, instead of adding it.

Template

{  
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",  
    "contentVersion": "1.0.0.0",  
    "parameters": {  
        "hostpoolname": {  
            "defaultValue": "",  
            "type": "string"  
        },  
        "appgroupname": {  
            "defaultValue": "",  
            "type": "string"  
        },  
        "workSpaceName": {  
            "defaultValue": "",  
            "type": "string"  
        },  
        "workspaceLocation": {  
            "type": "string",  
            "defaultValue": "eastus"  
        },  
        "workspaceResourceGroup": {  
            "type": "string",  
            "defaultValue": ""  
        },  
        "isNewWorkspace": {  
            "type": "bool",  
            "defaultValue": false  
        },  
        "allApplicationGroupReferences": {  
            "type": "string",  
            "defaultValue": ""  
        },  
        "addToWorkspace": {  
            "type": "bool",  
            "defaultValue": true  
        },  
        "deploymentId": {  
            "type": "string",  
            "defaultValue": ""  
        },  
        "apiVersion": {  
            "type": "string",  
            "defaultValue": "2019-12-10-preview"  
        }  
    },  
    "variables": {  
        "appGroupName": "[concat(parameters('hostpoolName'),'-DAG')]",  
        "appGroupResourceId": "[createArray(resourceId('Microsoft.DesktopVirtualization/applicationgroups/', variables('appGroupName')))]",  
        "applicationGroupReferencesArr": "[if(equals('',parameters('allApplicationGroupReferences')), variables('appGroupResourceId'), concat(split(parameters('allApplicationGroupReferences'),','), variables('appGroupResourceId')))]"  
    },  
    "resources": [  
        {  
            "type": "Microsoft.DesktopVirtualization/hostpools",  
            "apiVersion": "2022-04-01-preview",  
            "name": "[parameters('hostpoolname')]",  
            "location": "eastus",  
            "properties": {  
                "publicNetworkAccess": "Enabled",  
                "friendlyName": "Friendly Name",  
                "description": "Description",  
                "hostPoolType": "Pooled",  
                "customRdpProperty": "authentication level:i:0;drivestoredirect:s:*;audiomode:i:0;videoplaybackmode:i:1;redirectclipboard:i:1;redirectprinters:i:1;devicestoredirect:s:*;redirectcomports:i:1;redirectsmartcards:i:1;usbdevicestoredirect:s:*;enablecredsspsupport:i:1;use multimon:i:1;audiocapturemode:i:1;camerastoredirect:s:*;",  
                "maxSessionLimit": 1,  
                "loadBalancerType": "DepthFirst",  
                "validationEnvironment": false,  
                "preferredAppGroupType": "Desktop",  
                "startVMOnConnect": false  
            }  
        },  
        {  
            "type": "Microsoft.DesktopVirtualization/applicationgroups",  
            "apiVersion": "2022-04-01-preview",  
            "name": "[variables('appgroupname')]",  
            "location": "eastus",  
            "kind": "Desktop",  
            "properties": {  
                "hostpoolarmpath": "[resourceId('Microsoft.DesktopVirtualization/hostpools/', parameters('hostpoolName'))]",  
                "description": "Description",  
                "friendlyName": "Friendly Name",  
                "applicationGroupType": "Desktop"  
            },  
            "dependsOn": [  
                "[resourceId('Microsoft.DesktopVirtualization/hostpools/', parameters('hostpoolname'))]"  
            ]  
        },  
        {  
            "apiVersion": "2018-05-01",  
            "name": "[concat('Workspace-linkedTemplate-', parameters('deploymentId'))]",  
            "type": "Microsoft.Resources/deployments",  
            "resourceGroup": "[parameters('workspaceResourceGroup')]",  
            "condition": "[parameters('addToWorkspace')]",  
            "properties": {  
                "mode": "Incremental",  
                "template": {  
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",  
                    "contentVersion": "1.0.0.0",  
                    "resources": [  
                        {  
                            "apiVersion": "[parameters('apiVersion')]",  
                            "name": "[parameters('workSpaceName')]",  
                            "type": "Microsoft.DesktopVirtualization/workspaces",  
                            "location": "[parameters('workspaceLocation')]",  
                            "properties": {  
                                "applicationGroupReferences": "[variables('applicationGroupReferencesArr')]"  
                            }  
                        }  
                    ]  
                }  
            },  
            "dependsOn": [  
                "[resourceId('Microsoft.DesktopVirtualization/applicationgroups/', variables('appGroupName'))]"  
            ]  
        }  
    ]  
}  

I do have a workaround for making it work, but it is a little more command line magic than I'd like.

#set the variables  
$strRG = "ResourceGroup"  
$strWorkSpace = "TestWorkspace"  
$strHostPoolName = "TestPool018"  
  
#this code is important, without it you can overwrite the existing application groups in the workspace  
$arrAppGroups = (Get-AzWvdWorkspace -ResourceGroupName $strRG -Name $strWorkSpace).ApplicationGroupReference  
$strAppGroups = $arrAppGroups -join ","  
  
#deploy  
New-AzResourceGroupDeployment -ResourceGroupName $strRG -TemplateFile .\TestPooledTemplate.json -hostpoolname $strHostPoolName -workSpaceName $strWorkSpace -workspaceResourceGroup $strRG -allApplicationGroupReferences $strAppGroups  
  
  

Is there a way I can pull the workspace applicationGroupReferences in the template?

Thanks,
Joe

Azure Virtual Desktop
Azure Virtual Desktop
A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.
1,853 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. srbhatta-MSFT 8,586 Reputation points Microsoft Employee
    2022-12-13T05:48:44.73+00:00

    Hello @Joseph M. Durnal ,
    Welcome to Microsoft QnA.
    I did some research on this and I do not think there is a way you can pull the app group's references in the ARM template itself. You will have to do it via cli itself as you have already done.
    Let me know if you find a way! Thank you.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.