Hello @Marco Antonio Da Silva
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are in need to create terraform script to deploy application gateway.
Solution
Creating a Terraform script to deploy an Azure Application Gateway involves defining the necessary resources in a Terraform configuration file starting from:
- Set up your provider to ensure you have the Azure provider set up in your Terraform configuration
- Also, you will need to define various Azure resources including the resource group, virtual network, subnet, public IP, and the application gateway itself.
If you're able to do the above by follow any Microsoft guide, that will be cool.
However, this is a sample script for your use:
# Configure the Azure provider
provider "azurerm" {
features {}
}
# Create a resource group
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
# Create a virtual network
resource "azurerm_virtual_network" "example" {
name = "example-network"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
address_space = ["10.0.0.0/16"]
}
# Create a subnet within the virtual network
resource "azurerm_subnet" "example" {
name = "example-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.1.0/24"]
}
# Create a public IP
resource "azurerm_public_ip" "example" {
name = "example-pip"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
allocation_method = "Dynamic"
}
# Create the Application Gateway
resource "azurerm_application_gateway" "example" {
name = "example-appgateway"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku {
name = "Standard_Small"
tier = "Standard"
capacity = 2
}
gateway_ip_configuration {
name = "my-gateway-ip-configuration"
subnet_id = azurerm_subnet.example.id
}
frontend_port {
name = "my-frontend-port"
port = 80
}
frontend_ip_configuration {
name = "my-frontend-ip-configuration"
public_ip_address_id = azurerm_public_ip.example.id
}
backend_address_pool {
name = "my-backend-address-pool"
}
backend_http_settings {
name = "my-backend-http-settings"
cookie_based_affinity = "Disabled"
port = 80
protocol = "Http"
request_timeout = 1
}
http_listener {
name = "my-http-listener"
frontend_ip_configuration_name = "my-frontend-ip-configuration"
frontend_port_name = "my-frontend-port"
protocol = "Http"
}
request_routing_rule {
name = "my-request-routing-rule"
rule_type = "Basic"
http_listener_name = "my-http-listener"
backend_address_pool_name = "my-backend-address-pool"
backend_http_settings_name = "my-backend-http-settings"
}
}
This is a basic example on how to create script terraform to deploy application gateway.
This script creates an Azure resource group, a virtual network with a subnet, a public IP, and an application gateway with basic routing. You will have to replace "West Europe"
with your preferred Azure region.
Also, remember to initialize Terraform before applying the script using: terraform init
and
terraform apply
References
If you're new to Terraform, you might want to familiarize yourself with its syntax and commands on https://www.terraform.io/docs/cli/index.html.
Source: Build an Azure Application Gateway with Terraform. Accessed, 5/29/2024.
Source: Direct web traffic with Azure Application Gateway using Terraform. Accessed, 5/29/2024.
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam