|
| 1 | +--- |
| 2 | +title: 'Quickstart: Use Terraform to configure an Azure App Service Environment v3' |
| 3 | +description: In this quickstart, you learn how to configure an Azure App Service Environment v3. |
| 4 | +ms.topic: quickstart |
| 5 | +ms.date: 04/08/2025 |
| 6 | +ms.custom: devx-track-terraform |
| 7 | +ms.service: azure-app-service |
| 8 | +author: cephalin |
| 9 | +ms.author: cephalin |
| 10 | +#customer intent: As a Terraform user, I want to learn how to configure an Azure App Service Environment v3. |
| 11 | +content_well_notification: |
| 12 | + - AI-contribution |
| 13 | +--- |
| 14 | + |
| 15 | +# Quickstart: Use Terraform to configure an Azure App Service Environment v3 |
| 16 | + |
| 17 | +In this quickstart, you use [Terraform](/azure/developer/terraform) to create an App Service Environment, single-tenant deployment of Azure App Service. You use it with an Azure virtual network. You need one subnet for a deployment of App Service Environment, and this subnet can't be used for anything else. You create a resource group, virtual network, and a subnet to configure an Azure App Service Environment v3. |
| 18 | + |
| 19 | +In this article, you learn how to: |
| 20 | + |
| 21 | +> [!div class="checklist"] |
| 22 | +> * Create an Azure resource group with a unique name. |
| 23 | +> * Establish a virtual network with a specified name and address. |
| 24 | +> * Generate a random name for the subnet, and create a subnet in the virtual network. |
| 25 | +> * Delegate the subnet to the Microsoft.Web/hostingEnvironments service. |
| 26 | +> * Generate a random name for the App Service Environment v3, and create an App Service Environment v3 in the subnet. |
| 27 | +> * Set the internal load-balancing mode for the App Service Environment v3. |
| 28 | +> * Set cluster settings for the App Service Environment v3. |
| 29 | +> * Tag the App Service Environment v3. |
| 30 | +> * Output the names of the resource group, virtual network, subnet, and App Service Environment v3. |
| 31 | +
|
| 32 | +## Prerequisites |
| 33 | + |
| 34 | +- An Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 35 | +- Terraform. For more information, see [Install and configure Terraform](/azure/developer/terraform/quickstart-configure). |
| 36 | + |
| 37 | +> [!IMPORTANT] |
| 38 | +> If you're using the 4.x azurerm provider, you must [explicitly specify the Azure subscription ID](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/4.0-upgrade-guide#specifying-subscription-id-is-now-mandatory) to authenticate to Azure before running the Terraform commands. |
| 39 | +> |
| 40 | +> One way to specify the Azure subscription ID without putting it in the `providers` block is to specify the subscription ID in an environment variable named `ARM_SUBSCRIPTION_ID`. |
| 41 | +> |
| 42 | +> For more information, see the [Azure provider reference documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#argument-reference). |
| 43 | +
|
| 44 | +## Implement the Terraform code |
| 45 | + |
| 46 | +The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-app-service-environment). 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-app-service-environment/TestRecord.md). See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform). |
| 47 | + |
| 48 | +1. Create a directory in which to test and run the sample Terraform code, and make it the current directory. |
| 49 | + |
| 50 | +1. Create a file named `main.tf`, and insert the following code: |
| 51 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-app-service-environment/main.tf"::: |
| 52 | + |
| 53 | +1. Create a file named `outputs.tf`, and insert the following code: |
| 54 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-app-service-environment/outputs.tf"::: |
| 55 | + |
| 56 | +1. Create a file named `providers.tf`, and insert the following code: |
| 57 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-app-service-environment/providers.tf"::: |
| 58 | + |
| 59 | +1. Create a file named `variables.tf`, and insert the following code: |
| 60 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-app-service-environment/variables.tf"::: |
| 61 | + |
| 62 | +## Initialize Terraform |
| 63 | + |
| 64 | +[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)] |
| 65 | + |
| 66 | +## Create a Terraform execution plan |
| 67 | + |
| 68 | +[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)] |
| 69 | + |
| 70 | +## Apply a Terraform execution plan |
| 71 | + |
| 72 | +[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)] |
| 73 | + |
| 74 | +## Verify the results |
| 75 | + |
| 76 | +### [Azure CLI](#tab/azure-cli) |
| 77 | + |
| 78 | +1. Get the Azure resource group name. |
| 79 | + |
| 80 | + ```console |
| 81 | + resource_group_name=$(terraform output -raw resource_group_name) |
| 82 | + ``` |
| 83 | + |
| 84 | +1. Get the virtual network name. |
| 85 | + |
| 86 | + ```console |
| 87 | + virtual_network_name=$(terraform output -raw virtual_network_name) |
| 88 | + ``` |
| 89 | + |
| 90 | +1. Get the subnet name. |
| 91 | + |
| 92 | + ```console |
| 93 | + subnet_name=$(terraform output -raw subnet_name) |
| 94 | + ``` |
| 95 | + |
| 96 | +1. Run `az appservice ase show` to view the App Service Environment v3. |
| 97 | + |
| 98 | + ```azurecli |
| 99 | + az appservice ase show --name $app_service_environment_v3_name --resource-group $resource_group_name |
| 100 | + ``` |
| 101 | + |
| 102 | +### [Azure PowerShell](#tab/azure-powershell) |
| 103 | + |
| 104 | +1. Get the Azure resource group name. |
| 105 | + |
| 106 | + ```console |
| 107 | + $resource_group_name=$(terraform output -raw resource_group_name) |
| 108 | + ``` |
| 109 | + |
| 110 | +1. Get the virtual network name. |
| 111 | + |
| 112 | + ```console |
| 113 | + $virtual_network_name=$(terraform output -virtual_network_name) |
| 114 | + ``` |
| 115 | + |
| 116 | +1. Get the subnet name. |
| 117 | + |
| 118 | + ```console |
| 119 | + $subnet_name=$(terraform output -subnet_name) |
| 120 | + ``` |
| 121 | + |
| 122 | +1. Run `Get-AzAppServiceEnvironment` to view the AKS cluster within the Azure Extended Zone. |
| 123 | + |
| 124 | + ```azurepowershell |
| 125 | + Get-AzAppServiceEnvironment -Name $app_service_environment_v3_name -ResourceGroupName $resource_group_name |
| 126 | + ``` |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Clean up resources |
| 131 | + |
| 132 | +[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)] |
| 133 | + |
| 134 | +## Troubleshoot Terraform on Azure |
| 135 | + |
| 136 | +[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot). |
| 137 | + |
| 138 | +## Next steps |
| 139 | + |
| 140 | +> [!div class="nextstepaction"] |
| 141 | +> [See more articles about Azure app service environment v3.](/search/?terms=Azure%20app%20service%20environment%20v3%20and%20terraform) |
0 commit comments