cloudposse / terraform-aws-alb

Terraform module to provision a standard ALB for HTTP/HTTP traffic
https://cloudposse.com/accelerate
Apache License 2.0
112 stars 124 forks source link

A target group ARN must be specified when disabling the default target group #134

Open theodorosidmar opened 1 year ago

theodorosidmar commented 1 year ago

Describe the Bug

I am creating an Application Load Balancer and I am setting default_target_group_enabled = false. However, when trying to apply my changes, Terraform outputs:

Error: creating ELBv2 Listener (arn:aws:elasticloadbalancing:us-east-1:xxx:loadbalancer/app/my-alb/f3a3728915895e61): ValidationError: A target group ARN must be specified

Checking the code it seems that a Target Group is required by the https listener.

Expected Behavior

I expected to create an Application Load Balancer without a Target Group. I didn't want to create a TG to make the https listener to work.

Additional Context

I am creating an ALB for redirect purposes.

module "alb" {
  source  = "cloudposse/alb/aws"
  version = "1.7.0"

  namespace   = "my-namespace"
  environment = "my-environment"

  load_balancer_name           = "my-alb-name"
  vpc_id                       = var.vpc_id
  subnet_ids                   = var.subnet_ids
  internal                     = false
  http_enabled                 = true
  https_enabled                = true
  http_redirect                = true
  https_ssl_policy             = "ELBSecurityPolicy-TLS-1-2-2017-01"
  access_logs_enabled          = false
  default_target_group_enabled = false
}

variable "rules" {
  description = "The redirect rules"
  type = map(object({
    host = string
  }))
}

resource "aws_lb_listener_rule" "this" {
  for_each = var.rules

  listener_arn = module.alb.https_listener_arn

  condition {
    host_header {
      values = [each.key]
    }
  }

  action {
    type = "redirect"
    redirect {
      host        = each.value.host
      path        = "/#{path}"
      query       = "#{query}"
      port        = 443
      protocol    = "HTTPS"
      status_code = "HTTP_301"
    }
  }
}

Terraform version:

$ tf --version
Terraform v1.3.1
on linux_amd64
getglad commented 1 year ago

@max-lobur @tbpoetke friendly bump on this - don't know if you have any insights. Thanks!

spazm commented 1 year ago

Happy Hactoberfest. I ran into this same problem and [#149] is the fix I'm running locally. Hope it helps :)