Search code examples
azureazure-resource-managerazure-traffic-managerazure-rm-template

How do I dynamically generate Traffic Manager endpoints in an ARM template?


I have an ARM template that creates an arbitrary number of Azure webapps using the copy construct, like so (non-relevant portions removed):

{
  "parameters": { 
    "numWebsites": {
      "type": "int",
      "defaultValue": 2
    }
  },
  "resources": [
    "name": "[concat('webapp-', copyIndex()]",
    "type": "Microsoft.Web/sites",
    "copy": {
      "name": "websitescopy",
      "count": "[parameters('numWebsites')]"
    }
  ]
}

I'd also like to create a Traffic Manager profile with an endpoint for each of the websites created. However, there doesn't seem to be a way to make use of copy in the Traffic Manager resource's endpoints parameter. All of the examples I've seen have the endpoints explicitly listed out, but I don't know how many webapps are being created ahead of time so that doesn't work for me.

How can I generate the endpoints in my template dynamically? I've tried using a copy statement in the trafficManagerProfiles resource, but that creates multiple profiles with a single endpoint each.


Solution

  • Here's an example of creating an external endpoint as a "child resource", the profile is created separately without any endpoints and then this resource adds the endpoint. It uses an external endpoint but should work just as well for a webapp and is compatible with the standard copy function.

    HtH, Gareth

        {
            "apiVersion": "2015-11-01",
            "type": "Microsoft.Network/trafficManagerProfiles/ExternalEndpoints",
            "name": "ExternalEndpointExample/endpoint1",
            "dependsOn": ["Microsoft.Network/trafficManagerProfiles/ExternalEndpointExample"],
            "location": "global",
            "properties": {
                "target": "ep1.microsoft.com",
                "endpointStatus": "Enabled",
                "endpointLocation": "northeurope"
            }
        }