0

I tried to RTFM in the usual place, but none of the examples in 101-application-gateway exhibited this pattern. I have a Solution Template ARM template that deploys N VMs. I need to cause an Azure Application Gateway to be provisioned and configured with BackendAddresses that refer to those N VMs. I am familiar with the copy and copyIndex() pattern, but I don't see how to apply it here. The examples have code like:

"backendAddressPools": [
    {
        "name": "appGatewayBackendPool",
        "properties": {
            "BackendAddresses": [
                {
                    "IpAddress": "[parameters('backendIpAddress1')]"
                },
                {
                    "IpAddress": "[parameters('backendIpAddress2')]"
                }
            ]
        }
    }
],

but I would like to do something like:

"backendAddressPools": [
    {
        "name": "appGatewayBackendPool",
        "properties": {
            "BackendAddresses": [
                {
                    "IpAddress": "[concat(variables('managedVMPrefix'), copyIndex(),variables('nicName'))]"
                }
            ]
        }
    }
],

I'm sure that won't work because I need N entries in the BackendAddressess array.

Any ideas how to do this?

Thanks,

Ed

edburns
  • 482
  • 1
  • 4
  • 13

1 Answers1

0

After looking at the reference docs for the copy facility, I realized this is the correct syntax:

"backendAddressPools": [
  {
    "name": "appGatewayBackendPool",
    "properties": {
        "copy": [{
      "name": "BackendAddresses",
      "count": "[parameters('numberOfInstances')]",
      "input": {
        "IpAddress": "[reference(concat(variables('managedVMPrefix'), copyIndex('BackendAddresses', 1), variables('publicIPAddressName'))).properties.ipAddress]"
      }
        }]
    }
  }
]

Given NumberOfInstances is 3 and reference(concat(variables('managedVMPrefix'), copyIndex('BackendAddresses'), variables('nicName'))) resolves to mspVM1publicIp, mspVM2publicIp, mspVM1publicIp, which itself is passed through the reference() function to yield 10.0.1.10, 10.0.1.11, 10.0.1.12, this produces the following output:

"backendAddressPools": [
  {
    "name": "appGatewayBackendPool",
    "properties": {
      "BackendAddresses": [
        {
          "IpAddress": "[10.0.1.10]"
        },
        {
          "IpAddress": "[10.0.1.11]"
        },
        {
          "IpAddress": "[10.0.1.12]"
        }
      ]
    }
  }

I must say I think the ARM template syntax is terribly difficult to work with, understand, and maintain, but maybe it gets easier with more experience.

edburns
  • 482
  • 1
  • 4
  • 13