title | titleSuffix | description | services | author | ms.author | ms.date | ms.topic | ms.service | ms.custom | content_well_notification | ai-usage | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Quickstart: Direct web traffic with Azure Application Gateway - Terraform |
Azure Application Gateway |
In this quickstart, you learn how to use Terraform to create an Azure Application Gateway that directs web traffic to virtual machines in a backend pool. |
application-gateway |
greg-lindsay |
greglin |
05/30/2024 |
quickstart |
application-gateway |
devx-track-terraform |
|
ai-assisted |
In this quickstart, you use Terraform to create an Azure Application Gateway. Then you test the application gateway to make sure it works correctly. The Standard v2 SKU is used in this example.
[!INCLUDE About Terraform]
[!div class="checklist"]
- Create an Azure resource group using azurerm_resource_group
- Create an Azure Virtual Network using azurerm_virtual_network
- Create an Azure subnet using azurerm_subnet
- Create an Azure public IP using azurerm_public_ip
- Create an Azure Application Gateway using azurerm_application_gateway
- Create an Azure network interface using azurerm_network_interface
- Create an Azure network interface application gateway backend address pool association using azurerm_network_interface_application_gateway_backend_address_pool_association
- Create an Azure Windows Virtual Machine using azurerm_windows_virtual_machine
- Create an Azure Virtual Machine Extension using azurerm_virtual_machine_extension
Note
Application Gateway frontend now supports dual-stack IP addresses (Preview). You can now create up to four frontend IP addresses: Two IPv4 addresses (public and private) and two IPv6 addresses (public and private).
Note
The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform.
See more articles and sample code showing how to use Terraform to manage Azure resources
-
Create a directory in which to test the sample Terraform code and make it the current directory.
-
Create a file named
providers.tf
and insert the following code::::code language="Terraform" source="~/terraform_samples/quickstart/101-application-gateway/providers.tf":::
-
Create a file named
main.tf
and insert the following code::::code language="Terraform" source="~/terraform_samples/quickstart/101-application-gateway/main.tf":::
Tip
You can modify values of the Name
and Tier
parameters under resource\applicationGateWay\main\sku
to use a different SKU. For example: Basic
.
-
Create a file named
variables.tf
and insert the following code::::code language="Terraform" source="~/terraform_samples/quickstart/101-application-gateway/variables.tf":::
-
Create a file named
outputs.tf
and insert the following code::::code language="Terraform" source="~/terraform_samples/quickstart/101-application-gateway/outputs.tf":::
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
-
When you apply the execution plan, Terraform displays the frontend public IP address. If you've cleared the screen, you can retrieve that value with the following Terraform command:
echo $(terraform output -raw gateway_frontend_ip)
-
Paste the public IP address into the address bar of your web browser. Refresh the browser to see the name of the virtual machine. A valid response verifies the application gateway is successfully created and can connect with the backend.
[!INCLUDE terraform-plan-destroy.md]
Troubleshoot common problems when using Terraform on Azure
[!div class="nextstepaction"] Learn more about using Application Gateway