For 2nd terraform apply command ipv6 and allocation id gets deleted and updated again in subnet mapping of aws_lb resource

Terraform CLI and Terraform AWS Provider Version

Terraform v0.12.31
AWS Provider v3.61.0

Affected Resource(s)

  • aws_lb

Terraform Configuration Files

We have used the same example as documented in Terraform document version 3.61.0
https://registry.terraform.io/providers/hashicorp/aws/2.70.0/docs/resources/lb

Note:

Please refer following code I have used this type of configuration:

resource "aws_lb" "example" {
  name               = "example"
  load_balancer_type = "network"

  subnet_mapping {
    subnet_id     = aws_subnet.example1.id
    allocation_id = aws_eip.example1.id
    ipv6_address = "2406:da14:f7:2076:ffff:ffff:ffff:621"
  }

  subnet_mapping {
    subnet_id     = aws_subnet.example2.id
    allocation_id = aws_eip.example2.id
    ipv6_address = "2406:da14:f7:2098:0202:FFFF:B31E:789"
  }
}

Expected Behavior

The NLB should be left untouched as there are no changes to the subnet mapping block.

Actual Behavior

The NLB is to be deleted and re-created every time as per the output. It seems this is related to the “optional” attributes allocation_id and ipv6_address in the subnet mapping. When the NLB is created as internet-facing with an EIP(allocation_id) and ipv6_address are specified together as terraform supports it and my ip_address_type is dualstack(dual-stack technology allows ISPs to process IPv4 and IPv6 data traffic simultaneously), I observed that NLB is deleted and re-created every time when 2nd time apply command is executed (For 1st apply it create resource successfully) and it goes in loop.
But when I specify them 1 at a time that means either ipv6_address or allocation_id in subnet_mapping block it works fine for 2nd apply command as well it does not delete and recreate NLB.

   - subnet_mapping { # forces replacement
          - ipv6_address = **"2406:da14:f7:2076:ffff:ffff:ffff:621"** -> null
          - subnet_id    = **"subnet-03165414de469764a"** -> null
        }
      - subnet_mapping { # forces replacement
          - ipv6_address = **"2406:da14:f7:2098:0202:FFFF:B31E:789"** -> null
          - subnet_id    = **"subnet-048e929778f74f8f1"** -> null
        }
      + subnet_mapping { # forces replacement
          + allocation_id = "eipalloc-0077c5560954cdac0"
          + ipv6_address  = **"2406:da14:f7:2098:0202:FFFF:B31E:789"**
          + outpost_id    = (known after apply)
          + subnet_id     = **"subnet-048e929778f74f8f1"**
        }
      + subnet_mapping { # forces replacement
          + allocation_id = "eipalloc-01d4ac5b2a8e7ed2a"
          + ipv6_address  = **"2406:da14:f7:2076:ffff:ffff:ffff:621"**
          + outpost_id    = (known after apply)
          + subnet_id     = **"subnet-03165414de469764a"**
        }
    }

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

You can also notice that it is actually not changing anything ipv6_address and allocation_id are the same after the update as well.

Steps to Reproduce

    1. terraform apply