diff --git a/.changelog/26320.txt b/.changelog/26320.txt new file mode 100644 index 00000000000..91d821a4425 --- /dev/null +++ b/.changelog/26320.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_lb_target_group: Add `ip_address_type` argument +``` diff --git a/internal/service/elbv2/target_group.go b/internal/service/elbv2/target_group.go index 09412de30ca..e4af752459e 100644 --- a/internal/service/elbv2/target_group.go +++ b/internal/service/elbv2/target_group.go @@ -256,6 +256,13 @@ func ResourceTargetGroup() *schema.Resource { }, }, }, + "ip_address_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(elbv2.TargetGroupIpAddressTypeEnum_Values(), false), + }, "target_type": { Type: schema.TypeString, Optional: true, @@ -318,6 +325,12 @@ func resourceTargetGroupCreate(d *schema.ResourceData, meta interface{}) error { params.ProtocolVersion = aws.String(d.Get("protocol_version").(string)) } params.VpcId = aws.String(d.Get("vpc_id").(string)) + + if d.Get("target_type").(string) == elbv2.TargetTypeEnumIp { + if _, ok := d.GetOk("ip_address_type"); ok { + params.IpAddressType = aws.String(d.Get("ip_address_type").(string)) + } + } } if healthChecks := d.Get("health_check").([]interface{}); len(healthChecks) == 1 { diff --git a/internal/service/elbv2/target_group_test.go b/internal/service/elbv2/target_group_test.go index 20b02357c61..30012974a85 100644 --- a/internal/service/elbv2/target_group_test.go +++ b/internal/service/elbv2/target_group_test.go @@ -254,6 +254,29 @@ func TestAccELBV2TargetGroup_HealthCheck_tcp(t *testing.T) { }) } +func TestAccELBV2TargetGroup_ipAddressType(t *testing.T) { + var targetGroup1 elbv2.TargetGroup + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_lb_target_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, elbv2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckTargetGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccTargetGroupConfig_ipAddressType(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckTargetGroupExists(resourceName, &targetGroup1), + resource.TestCheckResourceAttr(resourceName, "target_type", "ip"), + resource.TestCheckResourceAttr(resourceName, "ip_address_type", "ipv6"), + ), + }, + }, + }) +} + func TestAccELBV2TargetGroup_tls(t *testing.T) { var targetGroup1 elbv2.TargetGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2351,6 +2374,40 @@ resource "aws_vpc" "test" { `, rName) } +func testAccTargetGroupConfig_ipAddressType(rName string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } +} + +resource "aws_lb_target_group" "test" { + name = %[1]q + port = 443 + protocol = "TLS" + vpc_id = aws_vpc.test.id + + target_type = "ip" + ip_address_type = "ipv6" + + health_check { + interval = 10 + port = "traffic-port" + protocol = "TCP" + healthy_threshold = 3 + unhealthy_threshold = 3 + } + + tags = { + Name = %[1]q + } +} +`, rName) +} + func testAccTargetGroupConfig_protocolTLS(rName string) string { return fmt.Sprintf(` resource "aws_vpc" "test" { diff --git a/website/docs/r/lb_target_group.html.markdown b/website/docs/r/lb_target_group.html.markdown index cbd38e69030..a5aaf805f48 100644 --- a/website/docs/r/lb_target_group.html.markdown +++ b/website/docs/r/lb_target_group.html.markdown @@ -94,6 +94,7 @@ The following arguments are supported: Network Load Balancers do not support the `lambda` target type. Application Load Balancers do not support the `alb` target type. +* `ip_address_type` (Optional, forces new resource) The type of IP addresses used by the target group, only supported when target type is set to `ip`. Possible values are `ipv4` or `ipv6`. * `vpc_id` - (Optional, Forces new resource) Identifier of the VPC in which to create the target group. Required when `target_type` is `instance`, `ip` or `alb`. Does not apply when `target_type` is `lambda`. ### health_check