hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

Network Load Balancer listener TargetGroup cannot have weight #20163

Open abjrcode opened 3 years ago

abjrcode commented 3 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Terraform version: 1.0.2 AWS Provider Version: 3.49.0

Affected Resource(s)

Expected Behavior

When creating a listener for a network load balancer it shouldn't specify a weight value for the default forward action in the call to the AWS API.

Actual Behavior

An AWS error saying: You cannot specify a target group weight on load balancers of type 'network' It has a default value of 1 for default forward action which doesn't work with NLBs

References

engineertdog commented 1 year ago

Even on v4.38.0, this is still an issue a year later.

Code - https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/elbv2/listener.go#L236-L241

This is the first time looking at Go, and this project. So I'm not sure if we'd prefer to just remove the default, or change the default and the validation function.

jre21 commented 1 year ago

@ewbankkit This issue has sat untouched for a year and a half, renders the impacted terraform resource unusable, and seems like the fix should be straightforward. Any chance you can take a look at it?

josegonzalez commented 1 month ago

This issue still exists. The validation code is here.

Perhaps a fix would be to allow a value of -1 - so validation.IntBetween(-1, 999), - and then omit the value here if it is a negative value?

rob-orr commented 3 weeks ago

The valid values for weight are 0-999. When nothing is set for weight in Terraform, it defaults to 1. However, in AWS the default setting value is zero. When it is then explicitly set to zero in Terraform, the plan shows no modifications to the target_group, but the apply still fails with "You cannot specify a target group weight on load balancers of type 'network'".

We're trying to enable NLB target group stickiness, but cannot do so through Terraform because of this bug. This ticket has been open for over 3 years, and seems like it should be fixed by now!

For reference, we are using Terraform 1.9.5, and AWS provider 5.63.0.

cdschneider commented 3 days ago

I found that the default weight of 1 only seems to be applied when you use the forward block configuration on an aws_lb_listener resource. When I started to use the target_group_arn attribute instead, I no longer ran into this issue.

Configuration resulting in the Network Load Balancer listener TargetGroup cannot have weight error:

resource "aws_lb_listener" "this" {
  load_balancer_arn = aws_lb.nlb.arn

  default_action {
    type = "forward"

    forward {
      target_group {
        arn = aws_lb_target_group.foobar.arn
      }
    }
  }
}

Working configuration:

resource "aws_lb_listener" "this" {
  load_balancer_arn = aws_lb.nlb.arn

  default_action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.foobar.arn
  }
}

Using Terraform 1.9.x and provider version 5.64.0.