Exclude paths from terraform aws_lb_listener

520 views Asked by At

I have an aws_lb_listener that redirects all traffics to HTTPS but I would like to exclude certain paths. Is this possible? I only see a way to include not exclude.

resource "aws_lb_listener" "web_http" {
  load_balancer_arn = aws_lb.web.arn
  port              = "80"
  protocol          = "HTTP"

  default_action {
    type = "redirect"
    redirect {
      port        = "443"
      protocol    = "HTTPS"
      status_code = "HTTP_301" # permanent redirect
    }
  }
}
1

There are 1 answers

4
Ali Samji On

You could make the redirect-to-https have a low priority — or high order as aws_lb_listener calls it — and create separate actions for the paths you want to exclude with a higher priority so that they get evaluated first.