azure - 应用程序网关 request_routing_rules 不存在

标签 azure terraform azure-application-gateway

我正在尝试部署 azure 应用程序网关。我设置的配置如下:

resource "azurerm_application_gateway" "demo-app-gateway" {
  location = var.location
  resource_group_name = azurerm_resource_group.rg-hri-testing-env.name
  name = "demo-app-gateway"

  autoscale_configuration {
    max_capacity = 10
    min_capacity = 2
  }

  frontend_port {
    name = "port_443"
    port = 443
  }

  sku {
    name = "Standard_v2"
    tier = "Standard_v2"
  }

  frontend_ip_configuration {
    name                          = "appGwPublicFrontendIp"
    public_ip_address_id          = azurerm_public_ip.demo-app-gateway-public-ip.id
    private_ip_address_allocation = "Dynamic"
  }

  backend_http_settings {
    cookie_based_affinity               = "Disabled"
    name                                = "demo-http-settings"
    port                                = 443
    protocol                            = "Https"
    host_name                           = "apim.test.com"
    pick_host_name_from_backend_address = false
    path                                = "/external/"
    request_timeout                     = 20
    probe_name                          = "demo-apim-probe"
    trusted_root_certificate_names      = ["demo-trusted-root-ca-certificate"]
  }

  probe {
    interval                                  = 30
    name                                      = "demo-apim-probe"
    path                                      = "/status-0123456789abcdef"
    protocol                                  = "Https"
    timeout                                   = 30
    unhealthy_threshold                       = 3
    pick_host_name_from_backend_http_settings = true
    match {
      body = ""
      status_code = [
        "200-399"
      ]
    }
  }

  gateway_ip_configuration {
    name      = "appGatewayIpConfig"
    subnet_id = azurerm_subnet.GatewaSubnet.id
  }

  backend_address_pool {
    name      = "demo-backend-pool"
  }

  http_listener {
    frontend_ip_configuration_name = "appGwPublicFrontendIp"
    frontend_port_name             = "port_443"
    name                           = "demo-app-gateway-listener"
    protocol                       = "Https"
    require_sni                    = false
    ssl_certificate_name           = "demo-app-gateway-certificate"
  }

  ssl_certificate {
    data     = filebase64(var.ssl_certificate_path)
    name     = "demo-app-gateway-certificate"
    password = var.ssl_certificate_password
  }

  trusted_root_certificate {
    data = filebase64(var.ssl_certificate_path)
    name = "demo-trusted-root-ca-certificate"
  }

  request_routing_rule {
    http_listener_name         = "demo-app-gateway-listener"
    name                       = "demo-rule"
    rule_type                  = "Basic"
    backend_address_pool_name  = "demo-backend-pool"
    backend_http_settings_name = "demo-http-setting"
    
  }
}

但是当我运行 terraform apply 时,我收到此错误。

Error: creating/updating Application Gateway: (Name "demo-app-gateway" / Resource Group "rg-hri-testing-apim"): network.ApplicationGatewaysClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="InvalidResourceReference" Message="Resource /subscriptions/my-sub/resourceGroups/rg-hri-testing-apim/providers/Microsoft.Network/applicationGateways/demo-app-gateway/backendHttpSettingsCollection/demo-http-setting referenced by resource /subscriptions/mysub/resourceGroups/rg-hri-testing-apim/providers/Microsoft.Network/applicationGateways/demo-app-gateway/requestRoutingRules/demo-rule was not found. Please make sure that the referenced resource exists, and that both resources are in the same region." Details=[]

  on app-gateway-main.tf line 1, in resource "azurerm_application_gateway" "demo-app-gateway":
   1: resource "azurerm_application_gateway" "demo-app-gateway" {

导致错误的资源是未找到request_routing_rule,但令我困惑的是,在创建它之前是否正在寻找它?

任何人都可以帮助我理解我在这里做错了什么吗?

如果您需要更多信息,请告诉我。

非常感谢

最佳答案

请检查请求路由规则 block 引用的后端 HTTP 设置名称。您必须将其更改为 request_routing_rule 中的 demo-http-settings 才能解决该错误。

<小时/>

问题:

您正在使用以下作为后端 http 设置:

backend_http_settings {
    cookie_based_affinity               = "Disabled"
    name                                = "demo-http-settings"
    port                                = 443
    protocol                            = "Https"
    host_name                           = "apim.test.com"
    pick_host_name_from_backend_address = false
    path                                = "/external/"
    request_timeout                     = 20
    probe_name                          = "demo-apim-probe"
    trusted_root_certificate_names      = ["demo-trusted-root-ca-certificate"]
  }

但是在请求请求路由规则中引用它时您正在使用:

request_routing_rule {
    http_listener_name         = "demo-app-gateway-listener"
    name                       = "demo-rule"
    rule_type                  = "Basic"
    backend_address_pool_name  = "demo-backend-pool"
    backend_http_settings_name = "demo-http-setting"

正如您在 request_routing_rule 中指定的名称 backend_http_setting_name = demo-http-settings 并将其指定为 demo-http-setting 一样。它将出错,因为找不到后端 http 设置。

关于azure - 应用程序网关 request_routing_rules 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69094307/

相关文章:

wcf - Windows 8 上使用 Microsoft 帐户的 Azure ACS 2.0

azure - 逻辑应用 - 将 Blob 文件复制到本地服务器

azure - 在 Azure 中使用 terraform 创建 kubernetes 集群后,如何自动对其进行身份验证?

azure - 运行 terraform init 后无法查看 Terraform 提供程序文件

azure - 无法通过对等 VNET 访问 Azure 应用程序网关

azure - 当我发布到 Azure 时,Serilog WriteTo.RollingFile 似乎会创建 500 错误代码

Azure 上的 Nhibernate HiLo

terraform - 使用 Terraform 创建具有功能(IAM 身份验证、旋转主密码)的 RDS (Amazon Aurora PostgreSQL)

azure - Terraform-Azure-无法为应用程序网关 StandardV2 创建专用 IP 配置