Resource: aws_lb_listener_rule

hi guys

i am trying to create a listener rule in my TF code and to add sitckiness to the rule.

If i do it manually i can select 1 target and add the sitckiness but if i do from code i cannot.

checking Terraform Registry
under the forward block it says:
Forward Blocks (for forward ) support the following:

  • target_group - (Required) One or more target groups block.
  • stickiness - (Optional) The target group stickiness for the rule.

but if i add in code

resource "aws_lb_listener_rule" "alb_01_lis_rule_ezyuat_02" {
  listener_arn = aws_lb_listener.alb_01_lis_443.arn
  priority     = 1

  action {
    type             = "forward"
    
    forward {
      target_group {
        arn    = aws_lb_target_group.alb_01_tg_ezyuat.arn
        weight = 100
      }

      stickiness {
        enabled  = true
        duration = 14400
      }
    }
  }

  condition {
    path_pattern {
      values = ["/monitor"]
    }
  }

  condition {
    host_header {
      values = ["example.com"]
    }
  }
}

I get


│ Error: Insufficient target_group blocks

│ on custom.tf line 86, in resource “aws_lb_listener_rule” “alb_01_lis_rule_02”:
│ 86: forward {

│ At least 2 “target_group” blocks are required.

how to solve it?

I think this issue should be fixed when you remove weight = 100 from target group block.

Same problem here, could this be a TF bug?

Hey, I think we can have one target group only by using this more simple notation:

  action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.static.arn
  }

@ivanilves your solution is a quick workaround and works but it unfortunately doesn’t help with creating stickiness blocks or add weight values since those are only supported in a “forward {}” block.

Apparently adding 1 TG is an AWS API limitation as mentioned here: