Terraform(A)lb重定向http - > https

Lio*_*orH 3 terraform elastic-load-balancer

如果我做对了,lb_listener只接受forward作为有效的动作类型. https://www.terraform.io/docs/providers/aws/r/lb_listener.html 如何配置侦听器以将HTTP重定向到HTTPS?

即这是elb listener中所需的状态:

在此输入图像描述

yda*_*coR 8

此功能已添加到AWS提供程序,并随1.33.0一起发布.

以下是使用aws_lb_listener资源在负载均衡器侦听器上设置默认操作的方法:

resource "aws_lb" "front_end" {
  # ...
}

resource "aws_lb_listener" "front_end" {
  load_balancer_arn = "${aws_lb.front_end.arn}"
  port              = "80"
  protocol          = "HTTP"

  default_action {
    type = "redirect"

    redirect {
      port        = "443"
      protocol    = "HTTPS"
      status_code = "HTTP_301"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

您还可以使用aws_lb_listener_rule资源中的各个负载均衡器侦听器规则添加重定向和固定类型响应:

resource "aws_lb_listener_rule" "redirect_http_to_https" {
  listener_arn = "${aws_lb_listener.front_end.arn}"

  action {
    type = "redirect"

    redirect {
      port        = "443"
      protocol    = "HTTPS"
      status_code = "HTTP_301"
    }
  }

  condition {
    field  = "host-header"
    values = ["my-service.*.terraform.io"]
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 拉取请求看起来非常全面,快速浏览一下我看不出它有什么问题.如果它未在下一版本的AWS提供程序中发布,我会感到惊讶. (3认同)
  • 发布了,是的!https://github.com/terraform-providers/terraform-provider-aws/issues/5344#issuecomment-415138537 (2认同)