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

resource/lb_target_group: validate health check threshold for tcp protocol during plan #3782

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 aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ func resourceAwsLbTargetGroupCustomizeDiff(diff *schema.ResourceDiff, v interfac
// LB and is a first run
return fmt.Errorf("%s: custom timeout is not supported for target_groups with TCP protocol", diff.Id())
}
if healthCheck["healthy_threshold"].(int) != healthCheck["unhealthy_threshold"].(int) {
return fmt.Errorf("%s: healthy_threshold %d and unhealthy_threshold %d must be the same for target_groups with TCP protocol", diff.Id(), healthCheck["healthy_threshold"].(int), healthCheck["unhealthy_threshold"].(int))
}
}
}

Expand Down
35 changes: 35 additions & 0 deletions aws/resource_aws_lb_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func TestAccAWSLBTargetGroup_networkLB_TargetGroup(t *testing.T) {
resource.TestCheckResourceAttr("aws_lb_target_group.test", "tags.Name", "TestAcc_networkLB_TargetGroup"),
),
},
{
Config: testAccAWSLBTargetGroupConfig_typeTCPInvalidThreshold(targetGroupName),
ExpectError: regexp.MustCompile("healthy_threshold [0-9]+ and unhealthy_threshold [0-9]+ must be the same for target_groups with TCP protocol"),
},
{
Config: testAccAWSLBTargetGroupConfig_typeTCPThresholdUpdated(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down Expand Up @@ -1231,6 +1235,37 @@ resource "aws_vpc" "test" {
}`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_typeTCPInvalidThreshold(targetGroupName string) string {
return fmt.Sprintf(`resource "aws_lb_target_group" "test" {
name = "%s"
port = 8082
protocol = "TCP"
vpc_id = "${aws_vpc.test.id}"

deregistration_delay = 200

health_check {
interval = 10
port = "traffic-port"
protocol = "TCP"
healthy_threshold = 3
unhealthy_threshold = 4
}

tags {
Name = "TestAcc_networkLB_TargetGroup"
}
}

resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"

tags {
Name = "terraform-testacc-lb-target-group-type-tcp"
}
}`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_typeTCPThresholdUpdated(targetGroupName string) string {
return fmt.Sprintf(`resource "aws_lb_target_group" "test" {
name = "%s"
Expand Down