Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
theodorosidmar opened this issue Apr 14, 2023 · 2 comments · May be fixed by #149
Open

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

theodorosidmar opened this issue Apr 14, 2023 · 2 comments · May be fixed by #149
Labels
bug 🐛 An issue with the system

Comments

@theodorosidmar
Copy link

theodorosidmar commented Apr 14, 2023

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
@theodorosidmar theodorosidmar added the bug 🐛 An issue with the system label Apr 14, 2023
@getglad
Copy link

getglad commented Sep 7, 2023

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

spazm added a commit to spazm/terraform-aws-alb that referenced this issue Oct 25, 2023
…et_group.default when disabled

* disables aws_lb_listener.http_forward when default_target_group is not enabled
* disables aws_lb_listener.http_redirect when default_target_group is disabled unless default http response exists
* disables aws_lb_listener.https when default_target_group is disabled unless default secure https response exists

Fixes this Validation error when default_target_group_enabled == 0 :
```
module.alb.aws_lb_listener.http_forward[0]: Creating...
╷
│ Error: creating ELBv2 Listener
(arn:aws:elasticloadbalancing:...:...:loadbalancer/...):
ValidationError: A target group ARN must be specified
│       status code: 400, request id:
7cf9d727-fc77-4d32-a160-cbd175e16e20
│
│   with module.alb.aws_lb_listener.http_forward[0],
│   on .terraform/modules/alb/main.tf line 150, in resource
"aws_lb_listener" "http_forward":
│  150: resource "aws_lb_listener" "http_forward" {

```
@spazm
Copy link

spazm commented Oct 25, 2023

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

spazm added a commit to spazm/terraform-aws-alb that referenced this issue Oct 25, 2023
…et_group.default when disabled

* disables aws_lb_listener.http_forward when default_target_group is not enabled
* disables aws_lb_listener.http_redirect when default_target_group is disabled unless default http response exists
* disables aws_lb_listener.https when default_target_group is disabled unless default secure https response exists

Fixes this Validation error when default_target_group_enabled == 0 :
```
module.alb.aws_lb_listener.http_forward[0]: Creating...
╷
│ Error: creating ELBv2 Listener
(arn:aws:elasticloadbalancing:...:...:loadbalancer/...):
ValidationError: A target group ARN must be specified
│       status code: 400, request id:
7cf9d727-fc77-4d32-a160-cbd175e16e20
│
│   with module.alb.aws_lb_listener.http_forward[0],
│   on .terraform/modules/alb/main.tf line 150, in resource
"aws_lb_listener" "http_forward":
│  150: resource "aws_lb_listener" "http_forward" {

```
spazm added a commit to spazm/terraform-aws-alb that referenced this issue Oct 25, 2023
…et_group.default when disabled

* disables aws_lb_listener.http_forward when default_target_group is not enabled
* disables aws_lb_listener.http_redirect when default_target_group is disabled unless default http response exists
* disables aws_lb_listener.https when default_target_group is disabled unless default secure https response exists

Fixes this Validation error when default_target_group_enabled == 0 :
```
module.alb.aws_lb_listener.http_forward[0]: Creating...
╷
│ Error: creating ELBv2 Listener
(arn:aws:elasticloadbalancing:...:...:loadbalancer/...):
ValidationError: A target group ARN must be specified
│       status code: 400, request id:
7cf9d727-fc77-4d32-a160-cbd175e16e20
│
│   with module.alb.aws_lb_listener.http_forward[0],
│   on .terraform/modules/alb/main.tf line 150, in resource
"aws_lb_listener" "http_forward":
│  150: resource "aws_lb_listener" "http_forward" {

```
spazm added a commit to spazm/terraform-aws-alb that referenced this issue Nov 2, 2023
…fault is disabled

* disables aws_lb_listener.http_forward when default_target_group is not enabled
* target_group is required when type is 'redirect'

Fixes this Validation error when default_target_group_enabled == 0 :

```
module.alb.aws_lb_listener.http_forward[0]: Creating...
╷
│ Error: creating ELBv2 Listener
(arn:aws:elasticloadbalancing:...:...:loadbalancer/...):
ValidationError: A target group ARN must be specified
│       status code: 400, request id:
7cf9d727-fc77-4d32-a160-cbd175e16e20
│
│   with module.alb.aws_lb_listener.http_forward[0],
│   on .terraform/modules/alb/main.tf line 150, in resource
"aws_lb_listener" "http_forward":
│  150: resource "aws_lb_listener" "http_forward" {

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
3 participants