From 7d8f82319205f625adffdc1ad8d5c052f7f0c79e Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Tue, 16 Aug 2022 13:19:04 +0200 Subject: [PATCH 1/6] Add new argument: `ip_address_type` to elbv2 target group --- internal/service/elbv2/target_group.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 { From c54038c3dee2b43bf9ce239264d9a43a48297830 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Tue, 16 Aug 2022 13:19:16 +0200 Subject: [PATCH 2/6] Write a test to cover the new `ip_address_type` arg --- internal/service/elbv2/target_group_test.go | 57 +++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/internal/service/elbv2/target_group_test.go b/internal/service/elbv2/target_group_test.go index 20b02357c61..b4e092c0011 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" { From 026f4544b8b88e4e0531f6ed843d25a47394f580 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Tue, 16 Aug 2022 13:19:28 +0200 Subject: [PATCH 3/6] Update docs to include the new `ip_address_type` arg --- website/docs/r/lb_target_group.html.markdown | 1 + 1 file changed, 1 insertion(+) 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 From aeab2da0f12c902d7dccd330fa4247c18571be99 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Tue, 16 Aug 2022 13:22:50 +0200 Subject: [PATCH 4/6] Create 26320.txt --- .changelog/26320.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changelog/26320.txt diff --git a/.changelog/26320.txt b/.changelog/26320.txt new file mode 100644 index 00000000000..87af33b19e7 --- /dev/null +++ b/.changelog/26320.txt @@ -0,0 +1,4 @@ +```release-note:enhancement +resource/aws_lb_target_group: Add `ip_address_type` argument +``` + From 5ca384322a24b14d922c44a50fbeabc6c8ca804b Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Tue, 16 Aug 2022 13:23:05 +0200 Subject: [PATCH 5/6] Rm additional newline --- .changelog/26320.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/.changelog/26320.txt b/.changelog/26320.txt index 87af33b19e7..91d821a4425 100644 --- a/.changelog/26320.txt +++ b/.changelog/26320.txt @@ -1,4 +1,3 @@ ```release-note:enhancement resource/aws_lb_target_group: Add `ip_address_type` argument ``` - From 539ec9b4c05efae327b004e1bf6f33e33a8aa7c6 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Tue, 16 Aug 2022 13:30:52 +0200 Subject: [PATCH 6/6] fmt aws_lb_target_group args --- internal/service/elbv2/target_group_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/elbv2/target_group_test.go b/internal/service/elbv2/target_group_test.go index b4e092c0011..30012974a85 100644 --- a/internal/service/elbv2/target_group_test.go +++ b/internal/service/elbv2/target_group_test.go @@ -2385,10 +2385,10 @@ resource "aws_vpc" "test" { } resource "aws_lb_target_group" "test" { - name = %[1]q - port = 443 - protocol = "TLS" - vpc_id = aws_vpc.test.id + name = %[1]q + port = 443 + protocol = "TLS" + vpc_id = aws_vpc.test.id target_type = "ip" ip_address_type = "ipv6"