|
| 1 | +--- |
| 2 | +title: 'Quickstart: Create an Azure Traffic Manager profile using Terraform' |
| 3 | +description: 'In this article, you create an Azure Traffic Manager profile using Terraform' |
| 4 | +services: traffic-manager |
| 5 | +ms.topic: quickstart |
| 6 | +ms.custom: devx-track-terraform, ai-gen-docs |
| 7 | +ms.service: traffic-manager |
| 8 | +author: TomArcherMsft |
| 9 | +ms.author: tarcher |
| 10 | +ms.date: 4/19/2023 |
| 11 | +--- |
| 12 | + |
| 13 | +# Quickstart: Create an Azure Traffic Manager profile using Terraform |
| 14 | + |
| 15 | +This quickstart describes how to use Terraform to create a Traffic Manager profile with external endpoints using the performance routing method. |
| 16 | + |
| 17 | +[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)] |
| 18 | + |
| 19 | +In this article, you learn how to: |
| 20 | + |
| 21 | +> [!div class="checklist"] |
| 22 | +> * Create a random value for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet). |
| 23 | +> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group). |
| 24 | +> * Create a random value for the Azure Traffic Manager profile name using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string). |
| 25 | +> * Create a random value for the Azure Traffic Manager profile DNS config relative name using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string). |
| 26 | +> * Create an Azure Traffic Manager profile using [azurerm_traffic_manager_profile](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/traffic_manager_profile). |
| 27 | +> * Create two Azure Traffic Manager external endpoint using [azurerm_traffic_manager_external_endpoint](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/traffic_manager_external_endpoint). |
| 28 | +
|
| 29 | +[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)] |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure) |
| 34 | + |
| 35 | +## Implement the Terraform code |
| 36 | + |
| 37 | +> [!NOTE] |
| 38 | +> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-traffic-manager-external-endpoint). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/master/quickstart/101-traffic-manager-external-endpoint/TestRecord.md). |
| 39 | +> |
| 40 | +> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform) |
| 41 | +
|
| 42 | +1. Create a directory in which to test and run the sample Terraform code and make it the current directory. |
| 43 | + |
| 44 | +1. Create a file named `providers.tf` and insert the following code: |
| 45 | + |
| 46 | + [!code-terraform[master](~/terraform_samples/quickstart/101-traffic-manager-external-endpoint/providers.tf)] |
| 47 | + |
| 48 | +1. Create a file named `main.tf` and insert the following code: |
| 49 | + |
| 50 | + [!code-terraform[master](~/terraform_samples/quickstart/101-traffic-manager-external-endpoint/main.tf)] |
| 51 | + |
| 52 | +1. Create a file named `variables.tf` and insert the following code: |
| 53 | + |
| 54 | + [!code-terraform[master](~/terraform_samples/quickstart/101-traffic-manager-external-endpoint/variables.tf)] |
| 55 | + |
| 56 | +1. Create a file named `outputs.tf` and insert the following code: |
| 57 | + |
| 58 | + [!code-terraform[master](~/terraform_samples/quickstart/101-traffic-manager-external-endpoint/outputs.tf)] |
| 59 | + |
| 60 | +## Initialize Terraform |
| 61 | + |
| 62 | +[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)] |
| 63 | + |
| 64 | +## Create a Terraform execution plan |
| 65 | + |
| 66 | +[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)] |
| 67 | + |
| 68 | +## Apply a Terraform execution plan |
| 69 | + |
| 70 | +[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)] |
| 71 | + |
| 72 | +## Verify the results |
| 73 | + |
| 74 | +#### [Azure CLI](#tab/azure-cli) |
| 75 | + |
| 76 | +1. Get the Azure resource group name. |
| 77 | + |
| 78 | + ```console |
| 79 | + resource_group_name=$(terraform output -raw resource_group_name) |
| 80 | + ``` |
| 81 | + |
| 82 | +1. Get the Traffic Manager profile name. |
| 83 | + |
| 84 | + ```console |
| 85 | + |
| 86 | + ``` |
| 87 | + |
| 88 | +1. Run [az network traffic-manager profile show](/cli/azure/network/traffic-manager/profile#az-network-traffic-manager-profile-show) to display information about the new Traffic Manager profile. |
| 89 | + |
| 90 | + ```azurecli |
| 91 | + az network traffic-manager profile show \ |
| 92 | + --resource-group $resource_group_name \ |
| 93 | + --name $azurerm_traffic_manager_profile_name |
| 94 | + ``` |
| 95 | + |
| 96 | +#### [Azure PowerShell](#tab/azure-powershell) |
| 97 | + |
| 98 | +1. Get the Azure resource group name. |
| 99 | + |
| 100 | + ```console |
| 101 | + $resource_group_name=$(terraform output -raw resource_group_name) |
| 102 | + ``` |
| 103 | + |
| 104 | +1. Get the Traffic Manager profile name. |
| 105 | + |
| 106 | + ```console |
| 107 | + $azurerm_traffic_manager_profile_name=$(terraform output -raw azurerm_traffic_manager_profile_name) |
| 108 | + ``` |
| 109 | + |
| 110 | +1. Run [Get-AzTrafficManagerProfile](/powershell/module/az.trafficmanager/get-aztrafficmanagerprofile) to display information about the new Traffic Manager profile. |
| 111 | + |
| 112 | + ```azurepowershell |
| 113 | + Get-AzTrafficManagerProfile -ResourceGroupName $resource_group_name ` |
| 114 | + -Name $azurerm_traffic_manager_profile_name |
| 115 | + ``` |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## Clean up resources |
| 120 | + |
| 121 | +[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)] |
| 122 | + |
| 123 | +## Troubleshoot Terraform on Azure |
| 124 | + |
| 125 | +[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot) |
| 126 | + |
| 127 | +## Next steps |
| 128 | + |
| 129 | +> [!div class="nextstepaction"] |
| 130 | +> [Improve website response with Azure Traffic Manager](tutorial-traffic-manager-improve-website-response.md) |
0 commit comments