Quickstart: Create a Traffic Manager profile using an ARM template

This quickstart describes how to use an Azure Resource Manager template (ARM Template) to create a Traffic Manager profile with external endpoints using the performance routing method.

An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.

If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.

Button to deploy the Resource Manager template to Azure.

Prerequisites

If you don't have an Azure subscription, create a trial subscription before you begin.

Review the template

The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.25.53.49325",
      "templateHash": "17662726020644193974"
    }
  },
  "parameters": {
    "uniqueDnsName": {
      "type": "string",
      "metadata": {
        "description": "Relative DNS name for the traffic manager profile, must be globally unique."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Network/trafficmanagerprofiles",
      "apiVersion": "2022-04-01",
      "name": "ExternalEndpointExample",
      "location": "global",
      "properties": {
        "profileStatus": "Enabled",
        "trafficRoutingMethod": "Performance",
        "dnsConfig": {
          "relativeName": "[parameters('uniqueDnsName')]",
          "ttl": 30
        },
        "monitorConfig": {
          "protocol": "HTTPS",
          "port": 443,
          "path": "/",
          "expectedStatusCodeRanges": [
            {
              "min": 200,
              "max": 202
            },
            {
              "min": 301,
              "max": 302
            }
          ]
        },
        "endpoints": [
          {
            "type": "Microsoft.Network/TrafficManagerProfiles/ExternalEndpoints",
            "name": "endpoint1",
            "properties": {
              "target": "www.microsoft.com",
              "endpointStatus": "Enabled",
              "endpointLocation": "chinaeast2"
            }
          },
          {
            "type": "Microsoft.Network/TrafficManagerProfiles/ExternalEndpoints",
            "name": "endpoint2",
            "properties": {
              "target": "docs.microsoft.com",
              "endpointStatus": "Enabled",
              "endpointLocation": "chinaeast"
            }
          }
        ]
      }
    }
  ],
  "outputs": {
    "name": {
      "type": "string",
      "value": "ExternalEndpointExample"
    },
    "resourceGroupName": {
      "type": "string",
      "value": "[resourceGroup().name]"
    },
    "resourceId": {
      "type": "string",
      "value": "[resourceId('Microsoft.Network/trafficmanagerprofiles', 'ExternalEndpointExample')]"
    }
  }
}

One Azure resource is defined in the template:

To find more templates that are related to Azure Traffic Manager, see Azure Quickstart Templates.

Deploy the template

  1. Open your local PowerShell console with administrator priviledge, and run the following scripts.

    Connect-AzAccount -Environment AzureChinaCloud
    
    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. chinaeast)"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/traffic-manager-external-endpoint/azuredeploy.json"
    
    $resourceGroupName = "${projectName}rg"
    
    New-AzResourceGroup -Name $resourceGroupName -Location "$location"
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri
    
    Read-Host -Prompt "Press [ENTER] to continue ..."
    

    Wait until you see the prompt from the console.

    Note

    When we deploy resource with specified template file URI that starts with https://raw.githubusercontent.com/, the console will run in error like Unable to download deployment content sometime.

    We can follow the actions below to resolve the corresponding issue.

    1. Copy the template URI, convert the URI by changing the prefix, infix, and tempalte file name. For exsample: the origin URI is https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-sql-autoscale/azuredeploy.json

      Category Original value Converted value Action
      Prefix https://raw.githubusercontent.com https://github.com Update
      Infix blob Add before master or main branch name
      Template file name azuredeploy.json your download tempalte file name update

      After modified, the converted URI will show like https://github.com/Azure/azure-quickstart-templates/blob/master/101-cosmosdb-sql-autoscale/azuredeploy.json.

      Please be kindly noticed that some templates URI have been updated as https://github.com/Azure/azure-quickstart-template/quickstarts/{Microsoft_Resource_Provider_Name}/, you can follow the corresponding path regulation to update the original URI.

    2. Copy the converted URI and download the specific template content in Internet browsers manully.

    3. Modify the templates you downloaded or referenced from the GitHub Repo in order to fit in the Azure China 21Vianet Environment. For example, replace some endpoints -- "blob.core.windows.net" by "blob.core.chinacloudapi.cn", "cloudapp.azure.com" by "chinacloudapp.cn"; change some unsupported Location,VM images, VM sizes, SKU, and resource-provider's API Version when necessary.

    4. Replace the parameter of -TemplateUri with -TemplateFile for powershell or --template-uri with --template-file for CLI , then update the specified URI with the downloaded actual file name and run the script again.

      Language category Reference link Action
      PowerShell New-AzResourceGroupDeployment Replace -TemplateUri with -TemplateFile
      Follow the previous steps to download the -TemplateParameterUri content and repalce with -TemplateParameterFile in cmdlet when necessary.
      Azure CLI az deployment group create Replace --template-uri with --template-file
  2. Select Copy from the previous code block to copy the PowerShell script.

  3. Right-click the shell console pane and then select Paste.

  4. Enter the values.

    The template deployment creates a profile with two external endpoints. Endpoint1 uses a target endpoint of www.microsoft.com with the location in China North. Endpoint2 uses a target endpoint of learn.microsoft.com with the location in China East.

    The resource group name is the project name with rg appended.

    Note

    uniqueDNSname needs to be a globally unique name in order for the template to deploy successfully. If deployment fails, start over with Step 1.

    It takes a few minutes to deploy the template. When completed, the output is similar to:

    Azure Traffic Manager Resource Manager template PowerShell deployment output

Azure PowerShell is used to deploy the template. In addition to Azure PowerShell, you can also use the Azure portal, Azure CLI, and REST API. To learn other deployment methods, see Deploy templates.

Validate the deployment

  1. Determine the DNS name of the Traffic Manager profile using Get-AzTrafficManagerProfile.

    Get-AzTrafficManagerProfile -Name ExternalEndpointExample -ResourceGroupName $resourceGroupName | Select RelativeDnsName
    

    Copy the RelativeDnsName value. The DNS name of your Traffic Manager profile is <relativednsname>.trafficmanager.cn.

  2. From a local PowerShell run the following command by replacing the {relativeDNSname} variable with <relativednsname>.trafficmanager.cn.

    Resolve-DnsName -Name {relativeDNSname} | Select-Object NameHost | Select -First 1
    

    You should get a NameHost of either www.microsoft.com or learn.microsoft.com depending on which region is closer to you.

  3. To check if you can resolve to the other endpoint, disable the endpoint for the target you got in the last step. Replace the {endpointName} with either endpoint1 or endpoint2 to disable the target for www.microsoft.com or learn.microsoft.com respectively.

    Disable-AzTrafficManagerEndpoint -Name {endpointName} -Type ExternalEndpoints -ProfileName ExternalEndpointExample -ResourceGroupName $resourceGroupName -Force
    
  4. Run the command from Step 2 again in a local PowerShell. This time you should get the other NameHost for the other endpoint.

Clean up resources

When you no longer need the Traffic Manager profile, delete the resource group. This removes the Traffic Manager profile and all the related resources.

To delete the resource group, call the Remove-AzResourceGroup cmdlet:

Remove-AzResourceGroup -Name <your resource group name>

Next steps

In this quickstart, you created a Traffic Manager profile.

To learn more about routing traffic, continue to the Traffic Manager tutorials.