|
| 1 | +--- |
| 2 | +title: 'Quickstart: Create an Azure Traffic Manager profile - Bicep' |
| 3 | +description: This quickstart article describes how to create an Azure Traffic Manager profile by using Bicep. |
| 4 | +services: traffic-manager |
| 5 | +author: schaffererin |
| 6 | +ms.author: v-eschaffer |
| 7 | +ms.date: 06/20/2022 |
| 8 | +ms.topic: quickstart |
| 9 | +ms.service: traffic-manager |
| 10 | +ms.custom: devx-track-azurepowershell, subject-armqs, mode-arm |
| 11 | +--- |
| 12 | + |
| 13 | +# Quickstart: Create a Traffic Manager profile using Bicep |
| 14 | + |
| 15 | +This quickstart describes how to use Bicep to create a Traffic Manager profile with external endpoints using the performance routing method. |
| 16 | + |
| 17 | +[!INCLUDE [About Bicep](../../includes/resource-manager-quickstart-bicep-introduction.md)] |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 22 | + |
| 23 | +## Review the Bicep file |
| 24 | + |
| 25 | +The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/traffic-manager-external-endpoint). |
| 26 | + |
| 27 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.network/traffic-manager-external-endpoint/main.bicep"::: |
| 28 | + |
| 29 | +One Azure resource is defined in the Bicep file: |
| 30 | + |
| 31 | +* [**Microsoft.Network/trafficManagerProfiles**](/azure/templates/microsoft.network/trafficmanagerprofiles) |
| 32 | + |
| 33 | +## Deploy the Bicep file |
| 34 | + |
| 35 | +1. Save the Bicep file as **main.bicep** to your local computer. |
| 36 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 37 | + |
| 38 | + # [CLI](#tab/CLI) |
| 39 | + |
| 40 | + ```azurecli-interactive |
| 41 | + az group create --name exampleRG --location eastus |
| 42 | + az deployment group create --resource-group exampleRG --template-file main.bicep --parameters uniqueDnsName=<dns-name> |
| 43 | + ``` |
| 44 | +
|
| 45 | + # [PowerShell](#tab/PowerShell) |
| 46 | +
|
| 47 | + ```azurepowershell-interactive |
| 48 | + New-AzResourceGroup -Name exampleRG -Location eastus |
| 49 | + New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -uniqueDnsName "<dns-name>" |
| 50 | + ``` |
| 51 | +
|
| 52 | + --- |
| 53 | +
|
| 54 | + The Bicep file deployment creates a profile with two external endpoints. **Endpoint1** uses a target endpoint of `www.microsoft.com` with the location in **North Europe**. **Endpoint2** uses a target endpoint of `docs.microsoft.com` with the location in **South Central US**. |
| 55 | +
|
| 56 | + > [!NOTE] |
| 57 | + > **uniqueDNSname** needs to be a globally unique name in order for the Bicep file to deploy successfully. |
| 58 | +
|
| 59 | + When the deployment finishes, you'll see a message indicating the deployment succeeded. |
| 60 | +
|
| 61 | +## Validate the deployment |
| 62 | +
|
| 63 | +Use Azure CLI or Azure PowerShell to validate the deployment. |
| 64 | +
|
| 65 | +1. Determine the DNS name of the Traffic Manager profile. |
| 66 | +
|
| 67 | + # [CLI](#tab/CLI) |
| 68 | +
|
| 69 | + ```azurecli-interactive |
| 70 | + az network traffic-manager profile show --name ExternalEndpointExample --resource-group exampleRG |
| 71 | + ``` |
| 72 | +
|
| 73 | + From the output, copy the **fqdn** value. It'll be in the following format: `<relativeDnsName>.trafficmanager.net`. This value is also the DNS name of your Traffic Manager profile. |
| 74 | +
|
| 75 | + # [PowerShell](#tab/PowerShell) |
| 76 | +
|
| 77 | + ```azurepowershell-interactive |
| 78 | + Get-AzTrafficManagerProfile -Name ExternalEndpointExample -ResourceGroupName exampleRG | Select RelativeDnsName |
| 79 | + ``` |
| 80 | +
|
| 81 | + Copy the **RelativeDnsName** value. The DNS name of your Traffic Manager profile is `<relativeDnsName>.trafficmanager.net`. |
| 82 | +
|
| 83 | + --- |
| 84 | +
|
| 85 | +2. Run the following command by replacing the **{relativeDnsName}** variable with `<relativeDnsName>.trafficmanager.net`. |
| 86 | +
|
| 87 | + # [CLI](#tab/CLI) |
| 88 | +
|
| 89 | + ```azurecli-interactive |
| 90 | + nslookup -type=cname {relativeDnsName} |
| 91 | + ``` |
| 92 | +
|
| 93 | + You should get a canonical name of either `www.microsoft.com` or `docs.microsoft.com` depending on which region is closer to you. |
| 94 | +
|
| 95 | + # [PowerShell](#tab/PowerShell) |
| 96 | +
|
| 97 | + ```powershell-interactive |
| 98 | + Resolve-DnsName -Name {relativeDnsname} | Select-Object NameHost | Select -First 1 |
| 99 | + ``` |
| 100 | +
|
| 101 | + You should get a NameHost of either `www.microsoft.com` or `docs.microsoft.com` depending on which region is closer to you. |
| 102 | +
|
| 103 | + --- |
| 104 | +
|
| 105 | +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 `docs.microsoft.com` respectively. |
| 106 | +
|
| 107 | + # [CLI](#tab/CLI) |
| 108 | +
|
| 109 | + ```azurecli-interactive |
| 110 | + az network traffic-manager endpoint update --name {endpointName} --type externalEndpoints --profile-name ExternalEndpointExample --resource-group exampleRG --endpoint-status "Disabled" |
| 111 | + ``` |
| 112 | +
|
| 113 | + # [PowerShell](#tab/PowerShell) |
| 114 | +
|
| 115 | + ```azurepowershell-interactive |
| 116 | + Disable-AzTrafficManagerEndpoint -Name {endpointName} -Type ExternalEndpoints -ProfileName ExternalEndpointExample -ResourceGroupName exampleRG -Force |
| 117 | + ``` |
| 118 | +
|
| 119 | + --- |
| 120 | +
|
| 121 | +4. Run the command from Step 2 again in Azure CLI or Azure PowerShell. This time, you should get the other canonical name/NameHost for the other endpoint. |
| 122 | +
|
| 123 | +## Clean up resources |
| 124 | +
|
| 125 | +When you no longer need the Traffic Manager profile, use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group. This removes the Traffic Manager profile and all the related resources. |
| 126 | +
|
| 127 | +# [CLI](#tab/CLI) |
| 128 | +
|
| 129 | +```azurecli-interactive |
| 130 | +az group delete --name exampleRG |
| 131 | +``` |
| 132 | + |
| 133 | +# [PowerShell](#tab/PowerShell) |
| 134 | + |
| 135 | +```azurepowershell-interactive |
| 136 | +Remove-AzResourceGroup -Name exampleRG |
| 137 | +``` |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +## Next steps |
| 142 | + |
| 143 | +In this quickstart, you created a Traffic Manager profile using Bicep. |
| 144 | + |
| 145 | +To learn more about routing traffic, continue to the Traffic Manager tutorials. |
| 146 | + |
| 147 | +> [!div class="nextstepaction"] |
| 148 | +> [Traffic Manager tutorials](tutorial-traffic-manager-improve-website-response.md) |
0 commit comments