繁体   English   中英

使用 terraform 为 Azure 应用程序网关添加重定向规则

[英]Add redirect rule for Azure Appplication Gateway with terraform

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

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

以下是添加azurerm_application_gateway资源所需的内容列表:

  • 2 frontend_port(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
  }

...
}

根据此模板 ,应该在Terraform中缺少重定向规则属性。 所以我的猜测是-你不能。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM