Skip to content

Commit

Permalink
Merge pull request #26320 from bschaatsbergen/f/ip-address-type-suppo…
Browse files Browse the repository at this point in the history
…rt-to-target-group

Add `ip_address_type` support to elbv2 target group
  • Loading branch information
ewbankkit committed Aug 17, 2022
2 parents 80ad19e + 539ec9b commit 0d8282d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/26320.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_lb_target_group: Add `ip_address_type` argument
```
13 changes: 13 additions & 0 deletions internal/service/elbv2/target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
57 changes: 57 additions & 0 deletions internal/service/elbv2/target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/lb_target_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d8282d

Please sign in to comment.