Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable cross zone load balancing option to target group #29920

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/29920.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_lb_target_group: Add `load_balancing_cross_zone_enabled` argument
```
67 changes: 47 additions & 20 deletions internal/service/elbv2/target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ const (
// @SDKResource("aws_lb_target_group")
func ResourceTargetGroup() *schema.Resource {
return &schema.Resource{
// NLBs have restrictions on them at this time
CustomizeDiff: customdiff.Sequence(
resourceTargetGroupCustomizeDiff,
verify.SetTagsDiff,
),

CreateWithoutTimeout: resourceTargetGroupCreate,
ReadWithoutTimeout: resourceTargetGroupRead,
UpdateWithoutTimeout: resourceTargetGroupUpdate,
Expand All @@ -48,6 +42,12 @@ func ResourceTargetGroup() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

// NLBs have restrictions on them at this time
CustomizeDiff: customdiff.Sequence(
resourceTargetGroupCustomizeDiff,
verify.SetTagsDiff,
),

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand All @@ -57,6 +57,11 @@ func ResourceTargetGroup() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"connection_termination": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"deregistration_delay": {
Type: nullable.TypeNullableInt,
Optional: true,
Expand Down Expand Up @@ -133,6 +138,13 @@ func ResourceTargetGroup() *schema.Resource {
},
},
},
"ip_address_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(elbv2.TargetGroupIpAddressTypeEnum_Values(), false),
},
"lambda_multi_value_headers_enabled": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -147,6 +159,16 @@ func ResourceTargetGroup() *schema.Resource {
"least_outstanding_requests",
}, false),
},
"load_balancing_cross_zone_enabled": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"true",
"false",
"use_load_balancer_configuration",
}, false),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -210,11 +232,6 @@ func ResourceTargetGroup() *schema.Resource {
Optional: true,
Default: false,
},
"connection_termination": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"slow_start": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -264,13 +281,8 @@ func ResourceTargetGroup() *schema.Resource {
},
},
},
"ip_address_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(elbv2.TargetGroupIpAddressTypeEnum_Values(), false),
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
"target_failover": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -303,8 +315,6 @@ func ResourceTargetGroup() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringInSlice(elbv2.TargetTypeEnum_Values(), false),
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
"vpc_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -475,6 +485,13 @@ func resourceTargetGroupCreate(ctx context.Context, d *schema.ResourceData, meta
})
}

if v, ok := d.GetOk("load_balancing_cross_zone_enabled"); ok {
attrs = append(attrs, &elbv2.TargetGroupAttribute{
Key: aws.String("load_balancing.cross_zone.enabled"),
Value: aws.String(v.(string)),
})
}

if v, ok := d.GetOk("preserve_client_ip"); ok {
attrs = append(attrs, &elbv2.TargetGroupAttribute{
Key: aws.String("preserve_client_ip.enabled"),
Expand Down Expand Up @@ -767,6 +784,13 @@ func resourceTargetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta
})
}

if d.HasChange("load_balancing_cross_zone_enabled") {
attrs = append(attrs, &elbv2.TargetGroupAttribute{
Key: aws.String("load_balancing.cross_zone.enabled"),
Value: aws.String(d.Get("load_balancing_cross_zone_enabled").(string)),
})
}

if d.HasChange("target_failover") {
failoverBlock := d.Get("target_failover").([]interface{})
if len(failoverBlock) == 1 {
Expand Down Expand Up @@ -1093,6 +1117,9 @@ func flattenTargetGroupResource(ctx context.Context, d *schema.ResourceData, met
case "load_balancing.algorithm.type":
loadBalancingAlgorithm := aws.StringValue(attr.Value)
d.Set("load_balancing_algorithm_type", loadBalancingAlgorithm)
case "load_balancing.cross_zone.enabled":
loadBalancingCrossZoneEnabled := aws.StringValue(attr.Value)
d.Set("load_balancing_cross_zone_enabled", loadBalancingCrossZoneEnabled)
case "preserve_client_ip.enabled":
_, err := strconv.ParseBool(aws.StringValue(attr.Value))
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion internal/service/elbv2/target_group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func DataSourceTargetGroup() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"load_balancing_cross_zone_enabled": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -150,11 +154,11 @@ func DataSourceTargetGroup() *schema.Resource {
},
},
},
"tags": tftags.TagsSchemaComputed(),
"target_type": {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
"vpc_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -277,6 +281,9 @@ func dataSourceTargetGroupRead(ctx context.Context, d *schema.ResourceData, meta
case "load_balancing.algorithm.type":
loadBalancingAlgorithm := aws.StringValue(attr.Value)
d.Set("load_balancing_algorithm_type", loadBalancingAlgorithm)
case "load_balancing.cross_zone.enabled":
loadBalancingCrossZoneEnabled := aws.StringValue(attr.Value)
d.Set("load_balancing_cross_zone_enabled", loadBalancingCrossZoneEnabled)
case "preserve_client_ip.enabled":
_, err := strconv.ParseBool(aws.StringValue(attr.Value))
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions internal/service/elbv2/target_group_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccELBV2TargetGroupDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr(datasourceNameByARN, "protocol_version", "HTTP1"),
resource.TestCheckResourceAttrSet(datasourceNameByARN, "vpc_id"),
resource.TestCheckResourceAttrSet(datasourceNameByARN, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrSet(datasourceNameByARN, "load_balancing_cross_zone_enabled"),
resource.TestCheckResourceAttr(datasourceNameByARN, "deregistration_delay", "300"),
resource.TestCheckResourceAttr(datasourceNameByARN, "slow_start", "0"),
resource.TestCheckResourceAttr(datasourceNameByARN, "tags.%", "1"),
Expand All @@ -52,6 +53,7 @@ func TestAccELBV2TargetGroupDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr(datasourceNameByName, "port", "8080"),
resource.TestCheckResourceAttr(datasourceNameByName, "protocol", "HTTP"),
resource.TestCheckResourceAttrSet(datasourceNameByName, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrSet(datasourceNameByName, "load_balancing_cross_zone_enabled"),
resource.TestCheckResourceAttrSet(datasourceNameByName, "vpc_id"),
resource.TestCheckResourceAttr(datasourceNameByName, "deregistration_delay", "300"),
resource.TestCheckResourceAttr(datasourceNameByName, "slow_start", "0"),
Expand Down Expand Up @@ -93,6 +95,7 @@ func TestAccELBV2TargetGroupDataSource_appCookie(t *testing.T) {
resource.TestCheckResourceAttr(resourceNameArn, "protocol_version", "HTTP1"),
resource.TestCheckResourceAttrSet(resourceNameArn, "vpc_id"),
resource.TestCheckResourceAttrSet(resourceNameArn, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrSet(resourceNameArn, "load_balancing_cross_zone_enabled"),
resource.TestCheckResourceAttr(resourceNameArn, "deregistration_delay", "300"),
resource.TestCheckResourceAttr(resourceNameArn, "slow_start", "0"),
resource.TestCheckResourceAttr(resourceNameArn, "tags.%", "1"),
Expand Down Expand Up @@ -199,7 +202,7 @@ func TestAccELBV2TargetGroupDataSource_tags(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "arn_suffix", resourceTg1, "arn_suffix"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "id", resourceTg1, "id"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "load_balancing_algorithm_type", resourceTg1, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "load_balancing_algorithm_type", resourceTg1, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "load_balancing_cross_zone_enabled", resourceTg1, "load_balancing_cross_zone_enabled"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "health_check.#", resourceTg1, "health_check.#"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "health_check.0.path", resourceTg1, "health_check.0.path"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTag, "health_check.0.port", resourceTg1, "health_check.0.port"),
Expand All @@ -214,7 +217,7 @@ func TestAccELBV2TargetGroupDataSource_tags(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "arn_suffix", resourceTg2, "arn_suffix"),
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "id", resourceTg2, "id"),
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "load_balancing_algorithm_type", resourceTg2, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "load_balancing_algorithm_type", resourceTg2, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "load_balancing_cross_zone_enabled", resourceTg2, "load_balancing_cross_zone_enabled"),
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "health_check.#", resourceTg2, "health_check.#"),
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "health_check.0.path", resourceTg2, "health_check.0.path"),
resource.TestCheckResourceAttrPair(dataSourceMatchSecondTag, "health_check.0.port", resourceTg2, "health_check.0.port"),
Expand All @@ -229,7 +232,7 @@ func TestAccELBV2TargetGroupDataSource_tags(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "arn_suffix", resourceTg1, "arn_suffix"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "id", resourceTg1, "id"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "load_balancing_algorithm_type", resourceTg1, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "load_balancing_algorithm_type", resourceTg1, "load_balancing_algorithm_type"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "load_balancing_cross_zone_enabled", resourceTg1, "load_balancing_cross_zone_enabled"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "health_check.#", resourceTg1, "health_check.#"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "health_check.0.path", resourceTg1, "health_check.0.path"),
resource.TestCheckResourceAttrPair(dataSourceMatchFirstTagAndName, "health_check.0.port", resourceTg1, "health_check.0.port"),
Expand Down
Loading