此功能已添加到AWS提供程序中,并且
released with 1.33.0
.
下面是如何使用
aws_lb_listener
resource
:
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"
}
}
}
您还可以在
aws_lb_listener_rule
resource
:
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"]
}
}