I have a big question that I cannot find solution or explanation to it.
I found this diagram online regarding the implementation of an application gateway.
so I tried to make a replica of it using terraform, but than something hit me up and start raising questions and I couldn't find solution to it.
with terraform I have no problem to create the MainRG
the VNET
and GWSubnet
but I was wondering, how is possible that inside the MainRG
there is the AZSubnet
which contains another RG
this makes it a nested RG inside the MainRG. Is this an error?
Another question and problem I came across, is how to I assign a app service to a subnet?
here is the code I implemented so far:
app.tf
resource "azurerm_app_service_plan" "ASP-hri-prd-app-service" {
location = var.app-service-loc
name = "ASP-hri-prd-app-service"
resource_group_name = azurerm_resource_group.rg-hri-eur-app-service.name
sku {
size = "S1"
tier = "Standard"
}
}
resource "azurerm_app_service" "hri-prd-eur-app-testing" {
app_service_plan_id = azurerm_app_service_plan.ASP-hri-prd-app-service.id
location = var.app-service-loc
name = "hri-prd-eur-app-testing"
resource_group_name = azurerm_resource_group.rg-hri-eur-app-service.name
}
applicationGateway.tf
resource "azurerm_resource_group" "rg-hri-prd-eur-app-gate" {
location = var.location
name = "rg-hri-prd-eur-app-gate"
}
resource "azurerm_resource_group" "rg-hri-eur-app-service" {
location = var.app-service-loc
name = "app-service-testing"
}
locals {
backend_address_pool_name = "${azurerm_virtual_network.hri-prd-VNET.name}-beap"
frontend_port_name = "${azurerm_virtual_network.hri-prd-VNET.name}-feport"
frontend_ip_configuration_name = "${azurerm_virtual_network.hri-prd-VNET.name}-feip"
http_setting_name = "${azurerm_virtual_network.hri-prd-VNET.name}-be-htst"
listener_name = "${azurerm_virtual_network.hri-prd-VNET.name}-httplstn"
request_routing_rule_name = "${azurerm_virtual_network.hri-prd-VNET.name}-rqrt"
redirect_configuration_name = "${azurerm_virtual_network.hri-prd-VNET.name}-rdrcfg"
}
resource "azurerm_application_gateway" "network" {
name = "example-appgateway"
resource_group_name = "${azurerm_resource_group.rg-hri-prd-eur-app-gate.name}"
location = "${azurerm_resource_group.rg-hri-prd-eur-app-gate.location}"
sku {
name = "Standard_Small"
tier = "Standard"
capacity = 2
}
gateway_ip_configuration {
name = "my-gateway-ip-configuration"
subnet_id = "${azurerm_subnet.hri-prd-app-gate.id}"
}
frontend_port {
name = "${local.frontend_port_name}"
port = 80
}
frontend_ip_configuration {
name = "${local.frontend_ip_configuration_name}"
public_ip_address_id = "${azurerm_public_ip.hri-prd-gate-pip.id}"
}
backend_address_pool {
name = "${local.backend_address_pool_name}"
}
backend_http_settings {
name = "${local.http_setting_name}"
cookie_based_affinity = "Disabled"
path = "/path1/"
port = 80
protocol = "Http"
request_timeout = 1
}
http_listener {
name = "${local.listener_name}"
frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}"
frontend_port_name = "${local.frontend_port_name}"
protocol = "Http"
}
request_routing_rule {
name = "${local.request_routing_rule_name}"
rule_type = "Basic"
http_listener_name = "${local.listener_name}"
backend_address_pool_name = "${local.backend_address_pool_name}"
backend_http_settings_name = "${local.http_setting_name}"
}
}
network.tf
resource "azurerm_virtual_network" "hri-prd-VNET" {
address_space = ["10.1.0.0/16"]
location = var.location
name = "hri-prd-VNET"
resource_group_name = azurerm_resource_group.rg-hri-prd-eur-app-gate.name
}
resource "azurerm_subnet" "hri-prd-app-gate" {
name = "hri-prd-app-gateway-subnet"
resource_group_name = azurerm_resource_group.rg-hri-prd-eur-app-gate.name
virtual_network_name = azurerm_virtual_network.hri-prd-VNET.name
address_prefixes = ["10.1.0.0/24"]
}
resource "azurerm_public_ip" "hri-prd-gate-pip" {
allocation_method = "Dynamic"
location = var.location
name = "hri-prd-gate-pip"
resource_group_name = azurerm_resource_group.rg-hri-prd-eur-app-gate.name
}
I have 2 resource groups, one for the application gateway and one for the app service.
But still I don't understand how to make the app service resource group in a subnet of the application gateway resource group.