簡體   English   中英

ApplicationGatewaySubnetInboundTrafficBlockedByNetworkSecurityGroup 使用 terraform 銷毀資源時出錯

[英]ApplicationGatewaySubnetInboundTrafficBlockedByNetworkSecurityGroup error when destroying resources with terraform

我正在使用 terraform 創建 Azure 基礎設施。 我能夠在網關子網中創建 AppGateway。 AppGateway 需要 NSG 規則來訪問端口 65200 - 65535 上的所有訪問權限,我已添加 NSG。 我能夠與 AppGateway 后面的應用程序通信。 但是當我嘗試破壞完整的設置時,我的 jenkins 管道失敗,它說 -

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 代碼創建子網、NSG 和創建 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
     ]
   }

我在 AppGateway 和 NSG 之間添加了depends_on關系,因為 AppGateway 依賴於 NSG。 我需要幫助來使用 terraform 銷毀這些資源。

• The 'Destroy' task through the terraform code that you are using is failing because inbound connectivity from the Jenkins pipeline is not possible through the NSG to the Azure resources, ie, Application gateway in this case since the NSG is blocking the Jenkins pipeline access到端口 65200 – 65535 上的 Azure 資源

因此,由於您已在“網關”子網中部署了“應用程序網關” ,並且您已經允許通過 NSG 與部署在應用程序網關后面的應用程序進行入站網絡連接

• 因此,請確保此允許規則的優先級設置高於同一類別的拒絕規則。 此外,允許 TCP 端口 65200 - 65535 用於應用程序網關 v2 SKU,目標子網為“任何”,源為“GatewayManager”服務標簽,用於 Jenkins 管道和 Azure 資源管理器之間的通信

請檢查並確保 NSG 中的以下規則設置正確:-

a)無法阻止出站 Internet 連接。 NSG 中的默認出站規則允許 Internet 連接。

b)不要刪除默認的出站規則。

c)不要創建拒絕任何出站連接的其他出站規則。

d)必須允許來自目標子網為 Any 的“AzureLoadBalancer”標簽的流量。

最后,請檢查所有上述規則和配置的優先級,如果入站規則的優先級設置高於拒絕規則,則它們將無效 請找到以下快照供您參考:-

NSG 規則創建

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM