Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an Azure Traffic Manager endpoint using ARM templates?

I am attempting to add an endpoint to an existing Azure Traffic Manager. When deploying the template below with New-AzureRmResourceGroupDeployment it erases previous endpoint configurations.

Is it possible to add an endpoint to an existing Traffic Manager through ARM templates without removing the previous ones? Or is the recommendation to use the Azure PowerShell client instead?

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "trafficManagerName": {
            "type": "String"
        },
        "webAppName": {
            "type": "String"
        },
        "webAppLocationRegion": {
            "type": "String"
        },
        "monitorPath": {
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Network/trafficManagerProfiles",
            "name": "[parameters('trafficManagerName')]",
            "apiVersion": "2017-05-01",
            "location": "global",
            "properties": {
                "profileStatus": "Enabled",
                "trafficRoutingMethod": "Performance",
                "dnsConfig": {
                    "relativeName": "[parameters('trafficManagerName')]",
                    "ttl": 70
                },
                "monitorConfig": {
                    "protocol": "HTTPS",
                    "port": 443,
                    "path": "[parameters('monitorPath')]"
                },
                "endpoints": [
                    {
                        "name": "[parameters('webAppName')]",
                        "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints",
                        "properties": {
                            "endpointStatus": "Enabled",
                            "targetResourceId": "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]",
                            "weight": 1,
                            "priority": 1,
                            "endpointLocation": "[parameters('webAppLocationRegion')]"
                        }
                    }
                ]
            }
        }
    ]
}

As an analogy, it is possible to incrementally add access policies to Azure Key Vault like so:

{
  "type": "Microsoft.KeyVault/vaults/accessPolicies",
  "name": "[concat(parameters('keyVaultSettings').name, '/add')]", <!-- notice the "/add" -->
  "apiVersion": "2015-06-01",        
  "properties": {
      "mode": "Incremental", 
      "accessPolicies": [
        {
          "tenantId": "[reference(concat(resourceId('Microsoft.Web/sites', parameters('webAppName')),'/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').tenantId]",
          "objectId": "[reference(concat(resourceId('Microsoft.Web/sites', parameters('webAppName')),'/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').principalId]",
          "permissions": {
            "secrets": [
              "get",
              "list"
            ]
          }
        }
    ]
  }
}
like image 216
ksiomelo Avatar asked Feb 05 '18 19:02

ksiomelo


People also ask

How do I import an ARM template into Azure?

Import ARM Template to Resource Group To bring up the interface for deploying an ARM Template within the Azure Portal, just select “New” in the menu on the left side of the Portal, then search for “Template Deployment” within the Marketplace. Once found, select and create a new “Template Deployment.”


2 Answers

Yes, you can.

The trick is to understand that Traffic Manager endpoints are simultaneously both properties of the profile, but also child resources in their own right.

Your template can therefore deploy an endpoint as a child resource. This will not affect other endpoints or any other profile properties.

For an example, take a look at the Azure Traffic Manager / Web Apps sample in the template gallery.Traffic Manager template.

That sample uses a CopyIndex loop to deploy multiple endpoints incrementally, one for each Web App. You can simplify this, removing the loop, to incrementally add a single endpoint.

like image 96
Jonathan Avatar answered Nov 07 '22 23:11

Jonathan


It is posible, but due to the fact that the configuration is declarative you need to specify all the existing endpoints and add a new one to those, else they will get deleted like you observe.

anything not specified in the template will get removed ;)

like image 43
4c74356b41 Avatar answered Nov 07 '22 22:11

4c74356b41