Skip to content

Commit

Permalink
r/lb_target_group: fix compatibility with Network Load Balancers
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Nov 10, 2017
1 parent 86cca67 commit 5b1b3fc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
4 changes: 3 additions & 1 deletion aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ func flattenAwsLbTargetGroupResource(d *schema.ResourceData, meta interface{}, t
healthCheck["matcher"] = *targetGroup.Matcher.HttpCode
}

d.Set("health_check", []interface{}{healthCheck})
if err := d.Set("health_check", []interface{}{healthCheck}); err != nil {
log.Printf("[WARN] Error setting health check: %s", err)
}

attrResp, err := elbconn.DescribeTargetGroupAttributes(&elbv2.DescribeTargetGroupAttributesInput{
TargetGroupArn: aws.String(d.Id()),
Expand Down
46 changes: 40 additions & 6 deletions aws/resource_aws_lb_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ func TestAccAWSLBTargetGroup_basic(t *testing.T) {
})
}

func TestAccAWSLBTargetGroup_networkLB_TargetGroup(t *testing.T) {
var conf elbv2.TargetGroup
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_lb_target_group.test",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLBTargetGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLBTargetGroupConfig_typeTCP(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSLBTargetGroupExists("aws_lb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_lb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "name", targetGroupName),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "port", "8082"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "protocol", "TCP"),
resource.TestCheckResourceAttrSet("aws_lb_target_group.test", "vpc_id"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "deregistration_delay", "200"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.#", "1"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.interval", "30"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.port", "traffic-port"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.protocol", "TCP"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.timeout", "10"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.healthy_threshold", "3"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.unhealthy_threshold", "3"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "tags.%", "1"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "tags.Name", "TestAcc_networkLB_TargetGroup"),
),
},
},
})
}

func TestAccAWSLBTargetGroupBackwardsCompatibility(t *testing.T) {
var conf elbv2.TargetGroup
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -803,11 +838,6 @@ func testAccAWSLBTargetGroupConfig_typeTCP(targetGroupName string) string {
deregistration_delay = 200
stickiness {
type = "lb_cookie"
cookie_duration = 10000
}
health_check {
interval = 30
port = "traffic-port"
Expand All @@ -816,13 +846,17 @@ func testAccAWSLBTargetGroupConfig_typeTCP(targetGroupName string) string {
healthy_threshold = 3
unhealthy_threshold = 3
}
tags {
Name = "TestAcc_networkLB_TargetGroup"
}
}
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags {
TestName = "TestAccAWSLBtypeTCP"
Name = "TestAcc_networkLB_TargetGroup"
}
}`, targetGroupName)
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/lb_target_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The following arguments are supported:
* `protocol` - (Required) The protocol to use for routing traffic to the targets.
* `vpc_id` - (Required) The identifier of the VPC in which to create the target group.
* `deregistration_delay` - (Optional) The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused. The range is 0-3600 seconds. The default value is 300 seconds.
* `stickiness` - (Optional) A Stickiness block. Stickiness blocks are documented below.
* `stickiness` - (Optional) A Stickiness block. Stickiness blocks are documented below. `stickiness` is only valid if used with Load Balancers of type `Application`
* `health_check` - (Optional) A Health Check block. Health Check blocks are documented below.
* `tags` - (Optional) A mapping of tags to assign to the resource.

Expand Down

0 comments on commit 5b1b3fc

Please sign in to comment.