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.83k stars 9.17k forks source link

[Bug]: aws_lb NLB update from subnets to subnet_mapping fails with "You must specify a subnet ID for each subnet mapping" #40060

Open cbugneac-nex opened 2 hours ago

cbugneac-nex commented 2 hours ago

Terraform Core Version

1.9.8

AWS Provider Version

5.74.0

Affected Resource(s)

aws_lb

Expected Behavior

NLB to be updated successfully from using subnets to subnet_mapping attributes.

Actual Behavior

Throws an error from AWS.

Relevant Error/Panic Output Snippet

module.this.module.nlb_internal.aws_lb.this[0]: Modifying... [id=arn:aws:elasticloadbalancing:eu-west-1:***:loadbalancer/net/dev-nlb-internal/f498a7274cde294e]
╷
│ Error: setting ELBv2 Load Balancer (arn:aws:elasticloadbalancing:eu-west-1:***:loadbalancer/net/dev-nlb-internal/f498a7274cde294e) subnets: operation error Elastic Load Balancing v2: SetSubnets, https response error StatusCode: 400, RequestID: 3ef7d306-7df0-44ee-ae21-754690dce5a4, api error ValidationError: You must specify a subnet ID for each subnet mapping.
│
│   with module.this.module.nlb_internal.aws_lb.this[0],
│   on .terraform/modules/this.nlb_internal/modules/alb/aws_lb_this.tf line 1, in resource "aws_lb" "this":
│    1: resource "aws_lb" "this" {

Terraform Configuration Files

Initial with subnets:

resource "aws_lb" "test_nlb" {
  name               = "test-nlb"
  internal           = true
  load_balancer_type = "network"

  subnets            = [for subnet in aws_subnet.private : subnet.id]
}

Change with private IP addresses (using subnet_mapping):

resource "aws_lb" "test_nlb" {
  name               = "test-nlb"
  internal           = true
  load_balancer_type = "network"

  subnet_mapping {
    subnet_id            = aws_subnet.private1.id
    private_ipv4_address = "10.161.16.69"
  }

  subnet_mapping {
    subnet_id            = aws_subnet.private2.id
    private_ipv4_address = "10.1641.16.99"
  }
}

Steps to Reproduce

  1. Apply with subnets (see above snippet).
  2. Apply change with subnet_mapping.
  3. Plan and apply:
    
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
    ~ update in-place

Terraform will perform the following actions:

module.this.module.nlb_internal.aws_lb.this[0] will be updated in-place

~ resource "aws_lb" "this" { id = "arn:aws:elasticloadbalancing:eu-west-1:***:loadbalancer/net/dev-nlb-internal/f498a7274cde294e" name = "dev-nlb-internal" ~ subnets = [

Plan: 0 to add, 1 to change, 0 to destroy.



### Debug Output

_No response_

### Panic Output

_No response_

### Important Factoids

_No response_

### References

_No response_

### Would you like to implement a fix?

None
github-actions[bot] commented 2 hours ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue