Modify naming convention for Windows Virtual Desktop session hosts in ARM template file

[As of May 27, 2020]

Here is the Japanese edition.
https://logico-jp.io/2020/05/27/modify-naming-convention-for-session-hosts-in-wvd-arm-templates/

Recently I was asked the following question.

I would like to modify the naming convention used in Windows Virtual Desktop (WVD) ARM templated published in GitHub. For example, the digit in a sequential number is fixed to 5, and the sequential number starts at not 0 (ZERO) but 1000.

WVD ARM templates published in GitHub are found in the following URL. In this entry, I will handle the template in “Create and provision WVD host pool”.

ARM Templates for Remote Desktop Services deployments
https://github.com/Azure/RDS-Templates

When clicking “Deploy to Azure” in README.md, Azure portal opens like the screenshot below and we can specify parameters for WVD session hosts to be created. This ARM template covers from creating session host VMs, registering VMs to an AD domain, creating host pool, and registering VMs to the pool.

The customize points are listed below.

  • The sequential number starts at 0 (ZERO).
  • The digit in the sequential number is not fixed.
  • When specifying “SH-” as PREFIX, each VM resource name is as follows.
    SH-0
    SH-1

    SH-98
    SH-99
  • The sequential number starts at 1000 (One thousand).
  • The digit in the sequential number is fixed (5) and filled with 0 (zero).
  • When specifying “SH-” as PREFIX, each VM resource name is as follows.
    SH-01000
    SH-01001

    SH-01098
    SH-01099

To meet his/her requirements, I explored and modified the ARM template. I would like to write down what I modified. In this case, two functions “copyIndex” and “padLeft” are key.

copyIndex
https://docs.microsoft.com/azure/azure-resource-manager/templates/template-functions-numeric#copyindex
padLeft
https://docs.microsoft.com/azure/azure-resource-manager/templates/template-functions-string#padleft

README.md

First of all, URLs linked to “Deploy to Azure” icon should be modified to modified ARM template. In this case, line 3 and like 6 should be modified. to modify each URL, you have to supply URL encoded URL for ARM template.

mainTemplate.json

In this section, some strings are concatenated to create VM name, and counters are generated based on the number of VMs. To meet his/her requirements, the following modification are required. Each modification at other parts is also similar to this.

[Original]
concat(variables(’rdshPrefix’), copyIndex(’rdshVmNamesCopy’))

[Modified]
concat(variables(’rdshPrefix’), padLeft(copyIndex(’rdshVmNamesCopy’, 1000), 5, ’0’))

[Original]
concat(variables(’rdshPrefix’), copyindex(), ’-nic’)

[Modified]
concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’-nic’)

Line 464

[Original]
concat(variables(’rdshPrefix’), copyindex())

[Modified]
concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’))

Line 475

[Original]
concat(’Microsoft.Network/networkInterfaces/’, variables(’rdshPrefix’), copyindex(), ’-nic’)

[Modified]
concat(’Microsoft.Network/networkInterfaces/’, variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’-nic’)

[Original]
concat(variables(‘rdshPrefix’), copyindex())

[Modified]
concat(variables(‘rdshPrefix’), padLeft(copyIndex(1000),5,’0’))

[Original]
resourceId(’Microsoft.Network/networkInterfaces’, concat(variables(’rdshPrefix’), copyindex(), ’-nic’))

[Modified]
resourceId(’Microsoft.Network/networkInterfaces’, concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’-nic’))

Line 514

[Original]
concat(variables(’rdshPrefix’), copyindex(), ’/joindomain’)

[Modified]
concat(variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’), ’/joindomain’)

Line 517

[Original]
concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), copyindex())

[Modified]
concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), padLeft(copyindex(1000),5,’0’))

As zero (0) is hard coded in this line, we might indeed replace “0” with “01000” in the same manner. However, I dared to use functions to modify this line. Further modification would be easier when offsets and digits might be supplied as parameters.

[Original]
concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), ’0/extensions/joindomain’)

[Modified]
concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), padLeft(copyIndex(1000),5,’0’), ’/extensions/joindomain’)

While a host pool is created and the first VM is registered to the pool in the earlier section, the rest VMs are registered to the pool in this section. Therefore, the number of VMs registered in this section is less one than the total number of VMs, and “1” is specified for “offset” in the original ARM template. To meet the requirements, offset “1000 + 1” should be specified for “offset”. The same modification should be done (line 598).

Line 592

[Original]
concat(variables(’rdshPrefix’), copyindex(1), ’/dscextension’)

[Modified]
concat(variables(’rdshPrefix’), padLeft(copyIndex(add(1000, 1)), 5, ’0’), ’/dscextension’)

Line 598

[Original]
concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), copyindex(if(greater(parameters(’rdshNumberOfInstances’), 1), 1, 0)), ’/extensions/joindomain’)

[Modified]
concat(’Microsoft.Compute/virtualMachines/’, variables(’rdshPrefix’), padLeft(copyindex(if(greater(parameters(’rdshNumberOfInstances’), 1), add(1000,1), 0)), 5, ’0’), ’/extensions/joindomain’)

Cloud Solution Architect @Microsoft, focusing on Application Development. ❤️Java (JVM/GraalVM) and open source technologies. All views are my own. Ex-🥑.