I am creating Azure infra using terraform. I am able to create AppGateway in gateway subnet. The AppGateway required NSG rule to all access on ports 65200 - 65535, I have added the NSG. I am able to communicate with app behind AppGateway. But my jenkins pipeline fails when I try to destroy the complete setup, it says -
Error: Deleting Security Rule: (Name "AllowGatewayManagerInbound" / Network Security Group
Name "gateway" / Resource Group "primary"): network.SecurityRulesClient#Delete: Failure
sending request: StatusCode=400 -- Original Error:
Code="ApplicationGatewaySubnetInboundTrafficBlockedByNetworkSecurityGroup" Message="Network
security group /subscriptions/****/resourceGroups/primary/providers/Microsoft.Network/networkSecurityGroups
/gateway blocks incoming internet traffic on ports 65200 - 65535 to subnet
/subscriptions/****/resourceGroups/primary/providers/Microsoft.Network/virtualNetworks/primary/subnets/gateway,
associated with Application Gateway subscriptions/****/resourceGroups/primary/providers/Microsoft.Network/applicationGateways/primary-centralus.
This is not permitted for Application Gateways that have V2 Sku." Details=[]
Terraform code to create subnet, NSG and create AppGateway.
resource "azurerm_network_security_group" "gateway" {
name = "gateway"
location = var.location
resource_group_name = azurerm_resource_group.app.name
tags = var.tags
}
resource "azurerm_network_security_rule" "gateway_allow_gateway_manager_https_inbound" {
name = "AllowGatewayManagerInbound"
description = "Allow Azure application GatewayManager on management ports"
resource_group_name = azurerm_network_security_group.gateway.resource_group_name
network_security_group_name = azurerm_network_security_group.gateway.name
priority = 2510
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
source_address_prefix = "GatewayManager"
destination_port_range = "65200-65535"
destination_address_prefix = "*"
}
module "app_gateway" {
source = "../../modules/app_gateway"
name = "${azurerm_resource_group.app.name}-${var.location}"
location = azurerm_resource_group.app.location
resource_group_name = azurerm_resource_group.app.name
vnet_subnet_id = azurerm_subnet.gateway.id
app_public_dns_zone = local.app_public_dns_zone
a_record_domain_name = local.a_record_subdomain
key_vault = local.key_vault
ssl_certificates = local.ssl_certificates
env = local.suffix
tags = var.tags
depends_on = [
azurerm_network_security_group.gateway
]
}
I have added depends_on
relationship between AppGateway and NSG as AppGateway depends on NSG.
I need help to destry these resources using terraform.