Skip to content

Commit

Permalink
resource/aws_lb_target_group: Add lambda_multi_value_headers_enabled …
Browse files Browse the repository at this point in the history
…argument

Reference: #7637

Output from acceptance testing:

```
--- PASS: TestAccAWSALBTargetGroup_lambda (13.37s)
--- PASS: TestAccAWSALBTargetGroup_missingPortProtocolVpc (17.64s)
--- PASS: TestAccAWSALBTargetGroup_namePrefix (23.80s)
--- PASS: TestAccAWSALBTargetGroup_generatedName (24.12s)
--- PASS: TestAccAWSALBTargetGroup_basic (24.63s)
--- PASS: TestAccAWSALBTargetGroup_lambdaMultiValueHeadersEnabled (30.06s)
--- PASS: TestAccAWSALBTargetGroup_setAndUpdateSlowStart (39.47s)
--- PASS: TestAccAWSALBTargetGroup_tags (40.23s)
--- PASS: TestAccAWSALBTargetGroup_changeNameForceNew (41.56s)
--- PASS: TestAccAWSALBTargetGroup_changePortForceNew (41.67s)
--- PASS: TestAccAWSALBTargetGroup_changeVpcForceNew (43.88s)
--- PASS: TestAccAWSALBTargetGroup_updateHealthCheck (46.08s)
--- PASS: TestAccAWSALBTargetGroup_changeProtocolForceNew (52.34s)
--- PASS: TestAccAWSALBTargetGroup_updateSticknessEnabled (55.45s)
```
  • Loading branch information
bflad committed Feb 22, 2019
1 parent ac2fb77 commit 03849bc
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 21 deletions.
5 changes: 5 additions & 0 deletions aws/data_source_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func dataSourceAwsLbTargetGroup() *schema.Resource {
Computed: true,
},

"lambda_multi_value_headers_enabled": {
Type: schema.TypeBool,
Computed: true,
},

"slow_start": {
Type: schema.TypeInt,
Computed: true,
Expand Down
87 changes: 78 additions & 9 deletions aws/resource_aws_alb_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,20 +505,79 @@ func testAccCheckAWSALBTargetGroupDestroy(s *terraform.State) error {
}

func TestAccAWSALBTargetGroup_lambda(t *testing.T) {
var conf elbv2.TargetGroup
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
var targetGroup1 elbv2.TargetGroup
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_alb_target_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_alb_target_group.test",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSALBTargetGroupDestroy,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSALBTargetGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSALBTargetGroupConfig_lambda(targetGroupName),
Config: testAccAWSALBTargetGroupConfig_lambda(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "target_type", "lambda"),
testAccCheckAWSALBTargetGroupExists(resourceName, &targetGroup1),
resource.TestCheckResourceAttr(resourceName, "lambda_multi_value_headers_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "target_type", "lambda"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"deregistration_delay",
"proxy_protocol_v2",
"slow_start",
},
},
},
})
}

func TestAccAWSALBTargetGroup_lambdaMultiValueHeadersEnabled(t *testing.T) {
var targetGroup1 elbv2.TargetGroup
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_alb_target_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSALBTargetGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSALBTargetGroupConfig_lambdaMultiValueHeadersEnabled(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSALBTargetGroupExists(resourceName, &targetGroup1),
resource.TestCheckResourceAttr(resourceName, "lambda_multi_value_headers_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "target_type", "lambda"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"deregistration_delay",
"proxy_protocol_v2",
"slow_start",
},
},
{
Config: testAccAWSALBTargetGroupConfig_lambdaMultiValueHeadersEnabled(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSALBTargetGroupExists(resourceName, &targetGroup1),
resource.TestCheckResourceAttr(resourceName, "lambda_multi_value_headers_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "target_type", "lambda"),
),
},
{
Config: testAccAWSALBTargetGroupConfig_lambdaMultiValueHeadersEnabled(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSALBTargetGroupExists(resourceName, &targetGroup1),
resource.TestCheckResourceAttr(resourceName, "lambda_multi_value_headers_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "target_type", "lambda"),
),
},
},
Expand Down Expand Up @@ -918,6 +977,16 @@ func testAccAWSALBTargetGroupConfig_lambda(targetGroupName string) string {
}`, targetGroupName)
}

func testAccAWSALBTargetGroupConfig_lambdaMultiValueHeadersEnabled(rName string, lambdaMultiValueHadersEnabled bool) string {
return fmt.Sprintf(`
resource "aws_alb_target_group" "test" {
lambda_multi_value_headers_enabled = %[1]t
name = %[2]q
target_type = "lambda"
}
`, lambdaMultiValueHadersEnabled, rName)
}

func testAccAWSALBTargetGroupConfig_missing_port(targetGroupName string) string {
return fmt.Sprintf(`resource "aws_alb_target_group" "test" {
name = "%s"
Expand Down
44 changes: 32 additions & 12 deletions aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func resourceAwsLbTargetGroup() *schema.Resource {
Default: false,
},

"lambda_multi_value_headers_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"target_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -367,9 +373,10 @@ func resourceAwsLbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if d.Get("target_type").(string) != elbv2.TargetTypeEnumLambda {
var attrs []*elbv2.TargetGroupAttribute
var attrs []*elbv2.TargetGroupAttribute

switch d.Get("target_type").(string) {
case elbv2.TargetTypeEnumInstance, elbv2.TargetTypeEnumIp:
if d.HasChange("deregistration_delay") {
attrs = append(attrs, &elbv2.TargetGroupAttribute{
Key: aws.String("deregistration_delay.timeout_seconds"),
Expand All @@ -395,7 +402,7 @@ func resourceAwsLbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) er
// groups, so long as it's not enabled. This allows for better support for
// modules, but also means we need to completely skip sending the data to the
// API if it's defined on a TCP target group.
if d.HasChange("stickiness") && d.Get("protocol") != "TCP" && d.Get("target_type").(string) != elbv2.TargetTypeEnumLambda {
if d.HasChange("stickiness") && d.Get("protocol") != "TCP" {
stickinessBlocks := d.Get("stickiness").([]interface{})
if len(stickinessBlocks) == 1 {
stickiness := stickinessBlocks[0].(map[string]interface{})
Expand All @@ -420,17 +427,24 @@ func resourceAwsLbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) er
})
}
}
case elbv2.TargetTypeEnumLambda:
if d.HasChange("lambda_multi_value_headers_enabled") {
attrs = append(attrs, &elbv2.TargetGroupAttribute{
Key: aws.String("lambda.multi_value_headers.enabled"),
Value: aws.String(strconv.FormatBool(d.Get("lambda_multi_value_headers_enabled").(bool))),
})
}
}

if len(attrs) > 0 {
params := &elbv2.ModifyTargetGroupAttributesInput{
TargetGroupArn: aws.String(d.Id()),
Attributes: attrs,
}
if len(attrs) > 0 {
params := &elbv2.ModifyTargetGroupAttributesInput{
TargetGroupArn: aws.String(d.Id()),
Attributes: attrs,
}

_, err := elbconn.ModifyTargetGroupAttributes(params)
if err != nil {
return fmt.Errorf("Error modifying Target Group Attributes: %s", err)
}
_, err := elbconn.ModifyTargetGroupAttributes(params)
if err != nil {
return fmt.Errorf("Error modifying Target Group Attributes: %s", err)
}
}

Expand Down Expand Up @@ -551,6 +565,12 @@ func flattenAwsLbTargetGroupResource(d *schema.ResourceData, meta interface{}, t

for _, attr := range attrResp.Attributes {
switch aws.StringValue(attr.Key) {
case "lambda.multi_value_headers.enabled":
enabled, err := strconv.ParseBool(aws.StringValue(attr.Value))
if err != nil {
return fmt.Errorf("Error converting lambda.multi_value_headers.enabled to bool: %s", aws.StringValue(attr.Value))
}
d.Set("lambda_multi_value_headers_enabled", enabled)
case "proxy_protocol_v2.enabled":
enabled, err := strconv.ParseBool(aws.StringValue(attr.Value))
if err != nil {
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 @@ -66,6 +66,7 @@ The following arguments are supported:
* `vpc_id` - (Optional, Forces new resource) The identifier of the VPC in which to create the target group. Required when `target_type` is `instance` or `ip`. Does not apply when `target_type` is `lambda`.
* `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.
* `slow_start` - (Optional) The amount time for targets to warm up before the load balancer sends them a full share of requests. The range is 30-900 seconds or 0 to disable. The default value is 0 seconds.
* `lambda_multi_value_headers_enabled` - (Optional) Boolean whether the request and response headers exchanged between the load balancer and the Lambda function include arrays of values or strings. Only applies when `target_type` is `lambda`.
* `proxy_protocol_v2` - (Optional) Boolean to enable / disable support for proxy protocol v2 on Network Load Balancers. See [doc](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html#proxy-protocol) for more information.
* `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.
Expand Down

0 comments on commit 03849bc

Please sign in to comment.