【问题标题】:Add redirect rule for Azure Appplication Gateway with terraform使用 terraform 为 Azure 应用程序网关添加重定向规则
【发布时间】:2019-06-16 17:09:56
【问题描述】:

如何为 azurerm_application_gateway 添加重定向规则? 在 azure 门户上有一个“重定向配置”复选框,但因此我没有找到 terraform 元素。

【问题讨论】:

标签: azure terraform terraform-provider-azure


【解决方案1】:

所以现在可以从 terraform 使用 redirect_configuration 块,这是文档: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_gateway#redirect_configuration

这里列出了您需要添加 azurerm_application_gateway 资源的内容:

  • 2 个前端端口(一个用于 80 和 443)
  • 2个http_listener(Http和Https各一个)
  • 2个request_routing_rule(Http和Https各一个)
  • 1 redirect_configuration(从http重定向到https)

注意:如果您没有在 http_listener 上设置 host_name,您将不得不创建多个 frontend_port 块。

它看起来像这样:

resource "azurerm_application_gateway" "example" {
  ...

  # Https Port
  frontend_port {
    name = "port-https"
    port = 443
  }

  # Http Port
  frontend_port {
    name = "port-http"
    port = 80
  }

  # Https Listener
  http_listener {
    name                           = "https-listener"
    frontend_ip_configuration_name = "<frontend_ip_configuration_name>"
    frontend_port_name             = "port-https"
    host_name                      = "<host_name>"
    protocol                       = "Https"
    require_sni                    = true
    ssl_certificate_name           = "<ssl_certificate_name>"
  }

  # Http Listener
   http_listener {
    name                           = "http-listener"
    frontend_ip_configuration_name = "<frontend_ip_configuration_name>"
    frontend_port_name             = "port-http"
    host_name                      = "<host_name>"
    protocol                       = "Http"
  }

  # Request routing rule for Https
  request_routing_rule {
    name                       = "routing-https"
    http_listener_name         = "https-listener"
    backend_address_pool_name  = "<backend_address_pool_name>"
    backend_http_settings_name = "<backend_http_settings_name>"
    rule_type                  = "Basic"
  }

  # Request routing rule for Http
  request_routing_rule {
    name                        = "routing-http"
    http_listener_name          = "http-listener"
    redirect_configuration_name = "redirect-config-https"
    rule_type                   = "Basic"
  }

  # Request Configuration for Https
  redirect_configuration {
    name                 = "redirect-config-https"
    target_listener_name = "https-listener"
    redirect_type        = "Permanent"
    include_path         = true
    include_query_string = true
  }

...
}

【讨论】:

    【解决方案2】:

    根据this template,应该有一个在 terraform 中缺少的重定向规则属性。所以我的猜测是——你不能。

    感谢 cmets 中发布的链接,这是您应该跟踪的问题:https://github.com/terraform-providers/terraform-provider-azurerm/issues/1576

    【讨论】:

    • 谢谢我会订阅这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2022-07-28
    • 1970-01-01
    • 2022-10-25
    • 2020-04-12
    • 2019-04-02
    相关资源
    最近更新 更多