{"id":3500,"date":"2020-10-27T12:56:35","date_gmt":"2020-10-27T11:56:35","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=3500"},"modified":"2020-10-27T12:56:35","modified_gmt":"2020-10-27T11:56:35","slug":"conditional-nested-arm-template-to-add-wvd-application-group-to-workspace","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2020\/10\/conditional-nested-arm-template-to-add-wvd-application-group-to-workspace\/","title":{"rendered":"Conditional nested ARM template to add WVD application group to Workspace"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In <a rel=\"noreferrer noopener\" href=\"https:\/\/techcommunity.microsoft.com\/t5\/windows-it-pro-blog\/getting-started-windows-virtual-desktop-arm-based-azure-portal\/ba-p\/1374466\" target=\"_blank\">Windows Virtual Desktop<\/a> (ARM version), applications are part of application groups, which in turn get nested under Workspaces. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In an &#8216;Infra As Code&#8217; world these should be deployed through ARM templates (or Az Cli\/Ps scripts). I had a long wrestle with ARM today getting applications assigned to workspaces ONLY if they weren&#8217;t already assigned. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Azure throws a friendly 400 error if you try to add an app that already exists, and interestingly, the ARM &#8216;contains&#8217; function fails to properly evaluate WVD Workspace members when in a nested template.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, I had to resort to some trickery by converting it to a string. For anyone else wanting to incrementally attach application groups to workspaces, feel free to copy\/clone my template \ud83d\ude42<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/10\/appgroupwvdconditional.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1148\" height=\"407\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/10\/appgroupwvdconditional.png\" alt=\"\" class=\"wp-image-3504\" srcset=\"https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/10\/appgroupwvdconditional.png 1148w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/10\/appgroupwvdconditional-300x106.png 300w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/10\/appgroupwvdconditional-1024x363.png 1024w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2020\/10\/appgroupwvdconditional-768x272.png 768w\" sizes=\"auto, (max-width: 1148px) 100vw, 1148px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/blob\/master\/ARM%20templates\/add-WVDApplicationGroupToWorkspace.json\" target=\"_blank\" rel=\"noreferrer noopener\">Git source<\/a><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n{\n    \"$schema\": \"http:\/\/schema.management.azure.com\/schemas\/2014-04-01-preview\/deploymentTemplate.json#\",\n    \"contentVersion\": \"1.0.0.0\",\n    \"parameters\": {\n        \"workspaceName\": {\n            \"type\": \"string\",\n            \"metadata\": {\n                \"description\": \"The name of the Workspace.\"\n            },\n            \"defaultValue\": \"NLD-WVD-WS01\"\n        },\n        \"workspaceResourceGroup\": {\n            \"type\": \"string\",\n            \"metadata\": {\n                \"description\": \"The workspace resource group Name.\"\n            },\n            \"defaultValue\": \"WE-WVD-RG\"\n        },\n        \"appGroupName\": {\n            \"type\": \"string\",\n            \"metadata\": {\n                \"description\": \"The name of the Application Group to be linked.\"\n            },\n            \"defaultValue\": \"testag2\"\n        }\n    },\n    \"variables\": {\n        \"appGroupResourceId\": \"&#x5B;resourceId('Microsoft.DesktopVirtualization\/applicationgroups\/', parameters('appGroupName'))]\"\n    },\n    \"resources\": &#x5B;\n        {\n            \"apiVersion\": \"2018-05-01\",\n            \"name\": \"AddAppGroupToWorkspaceIncrementally\",\n            \"type\": \"Microsoft.Resources\/deployments\",\n            \"resourceGroup\": \"&#x5B;parameters('workspaceResourceGroup')]\",\n            \"properties\": {\n                \"mode\": \"Incremental\",\n                \"template\": {\n                    \"$schema\": \"https:\/\/schema.management.azure.com\/schemas\/2015-01-01\/deploymentTemplate.json#\",\n                    \"contentVersion\": \"1.0.0.0\",\n                    \"resources\": &#x5B;\n                        {\n                            \"name\": \"&#x5B;parameters('workspaceName')]\",\n                            \"apiVersion\": \"2019-12-10-preview\",\n                            \"condition\": \"&#x5B;not(greater(indexOf(string(reference(concat('\/subscriptions\/',subscription().subscriptionId,'\/resourceGroups\/',parameters('workspaceResourceGroup'),'\/providers\/Microsoft.DesktopVirtualization\/workspaces\/',parameters('workspaceName')),'2019-12-10-preview','Full').properties.applicationGroupReferences),variables('appGroupResourceId')),0))]\",\n                            \"type\": \"Microsoft.DesktopVirtualization\/workspaces\",\n                            \"location\": \"eastus\",\n                            \"properties\": {\n                                \"applicationGroupReferences\": \"&#x5B;union(reference(concat('\/subscriptions\/',subscription().subscriptionId,'\/resourceGroups\/',parameters('workspaceResourceGroup'),'\/providers\/Microsoft.DesktopVirtualization\/workspaces\/',parameters('workspaceName')),'2019-12-10-preview','Full').properties.applicationGroupReferences,array(variables('appGroupResourceId')))]\"\n                            }\n                        }\n                    ]\n                }\n            }\n        }        \n    ]\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Windows Virtual Desktop (ARM version), applications are part of application groups, which in turn get nested under Workspaces. In an &#8216;Infra As Code&#8217; world these should be deployed through ARM templates (or Az Cli\/Ps scripts). I had a long wrestle with ARM today getting applications assigned to workspaces ONLY if they weren&#8217;t already assigned. &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2020\/10\/conditional-nested-arm-template-to-add-wvd-application-group-to-workspace\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Conditional nested ARM template to add WVD application group to Workspace<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[49,6],"tags":[],"class_list":["post-3500","post","type-post","status-publish","format-standard","hentry","category-arm","category-windows-virtual-desktop"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=3500"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3500\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=3500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=3500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=3500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}