From 76a3ce971bd7074c099d05b605e239a57ca7f150 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Fri, 10 Nov 2017 12:33:36 -0600 Subject: [PATCH] r/lb_target_group: fix compatibility with Network Load Balancers --- aws/resource_aws_lb_target_group.go | 4 +- aws/resource_aws_lb_target_group_test.go | 46 +++++++++++++++++--- website/docs/r/lb_target_group.html.markdown | 2 +- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_lb_target_group.go b/aws/resource_aws_lb_target_group.go index f995a52c56d8..3717e4c1c23e 100644 --- a/aws/resource_aws_lb_target_group.go +++ b/aws/resource_aws_lb_target_group.go @@ -496,7 +496,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()), diff --git a/aws/resource_aws_lb_target_group_test.go b/aws/resource_aws_lb_target_group_test.go index ea0b81f62eb9..556dbadfdac9 100644 --- a/aws/resource_aws_lb_target_group_test.go +++ b/aws/resource_aws_lb_target_group_test.go @@ -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)) @@ -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" @@ -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) } diff --git a/website/docs/r/lb_target_group.html.markdown b/website/docs/r/lb_target_group.html.markdown index 15590ce58b03..1447ad3478d3 100644 --- a/website/docs/r/lb_target_group.html.markdown +++ b/website/docs/r/lb_target_group.html.markdown @@ -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.