Home > database >  terraform resource aws lb_listener blocks of type forward are not expected here
terraform resource aws lb_listener blocks of type forward are not expected here

Time:09-29

Trying to use this public module https://github.com/mineiros-io/terraform-aws-lb-listener for an aws lb_listener, I received this error:

in module "terraform-aws-lb-listener-443to80":
forward = {
 An argument named "forward" is not expected here.
Operation failed: failed running terraform plan (exit 1); 

when trying to use the module like this:

module "terraform-aws-lb-listener-443to80" {
  source = "[email protected]:mineiros-io/terraform-aws-lb-listener.git?ref=v0.0.1"

  port = "443"
  protocol = "HTTPS"
  ssl_policy = "ELBSecurityPolicy-2016-08"
  certificate_arn = data.aws_acm_certificate.general.arn
  load_balancer_arn = module.aws_alb.arn
  forward = {
    target_group = {
      arn = module.aws_lb_target_group_80.arn
    }
    target_group = {
      arn = module.aws_lb_target_group_ip.arn
    }
  }
}

I need a little guidance on how to use this module properly since the examples are currently lacking. I'm trying to associate 2 target groups to the listener & for that the forward block needs to be used.

CodePudding user response:

forward should be part of action:

module "terraform-aws-lb-listener-443to80" {
  source = "[email protected]:mineiros-io/terraform-aws-lb-listener.git?ref=v0.0.1"

  port = "443"
  protocol = "HTTPS"
  ssl_policy = "ELBSecurityPolicy-2016-08"
  certificate_arn = data.aws_acm_certificate.general.arn
  load_balancer_arn = module.aws_alb.arn

  action {

     forward = {
        target_groups = [
          {arn = module.aws_lb_target_group_80.arn},
          {arn = module.aws_lb_target_group_ip.arn}
        ]
      }
   }
}

Please check description of action on how to actually use it correctly.

CodePudding user response:

This is actually what worked for me. Some subtle changes to @Marcin answer but it definitely helped.

module "terraform-aws-lb-listener-443to80" {
  source = "[email protected]:mineiros-io/terraform-aws-lb-listener.git?ref=v0.0.1"
  port = "443"
  protocol = "HTTPS"
  ssl_policy = "ELBSecurityPolicy-2016-08"
  certificate_arn = data.aws_acm_certificate.general.arn
  load_balancer_arn = module.aws_alb.arn
  default_action = {
    type = "forward"
    forward = {
       target_groups = [
         {
           arn = module.aws_lb_target_group_80.arn
           #weight = 499
         },
         {
           arn = module.aws_lb_target_group_ip.arn
           #weight = 499
         }
       ]
    }
  }
}
  • Related