Skip to content

Commit

Permalink
Merge pull request #5681 from parabolic/Add_IncludeBody_for_lambda_fu…
Browse files Browse the repository at this point in the history
…nction_association

Add include body for lambda function association
  • Loading branch information
bflad authored Sep 12, 2018
2 parents f1d9ad7 + 855a1aa commit 5228cd1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ func lambdaFunctionAssociationHash(v interface{}) int {
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["event_type"].(string)))
buf.WriteString(fmt.Sprintf("%s", m["lambda_arn"].(string)))
buf.WriteString(fmt.Sprintf("%t", m["include_body"].(bool)))
return hashcode.String(buf.String())
}

Expand Down Expand Up @@ -553,6 +554,9 @@ func expandLambdaFunctionAssociation(lf map[string]interface{}) *cloudfront.Lamb
if v, ok := lf["lambda_arn"]; ok {
lfa.LambdaFunctionARN = aws.String(v.(string))
}
if v, ok := lf["include_body"]; ok {
lfa.IncludeBody = aws.Bool(v.(bool))
}
return &lfa
}

Expand All @@ -569,6 +573,7 @@ func flattenLambdaFunctionAssociation(lfa *cloudfront.LambdaFunctionAssociation)
if lfa != nil {
m["event_type"] = *lfa.EventType
m["lambda_arn"] = *lfa.LambdaFunctionARN
m["include_body"] = *lfa.IncludeBody
}
return m
}
Expand Down
10 changes: 6 additions & 4 deletions aws/cloudfront_distribution_configuration_structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ func trustedSignersConf() []interface{} {
func lambdaFunctionAssociationsConf() *schema.Set {
x := []interface{}{
map[string]interface{}{
"event_type": "viewer-request",
"lambda_arn": "arn:aws:lambda:us-east-1:999999999:function1:alias",
"event_type": "viewer-request",
"lambda_arn": "arn:aws:lambda:us-east-1:999999999:function1:alias",
"include_body": true,
},
map[string]interface{}{
"event_type": "origin-response",
"lambda_arn": "arn:aws:lambda:us-east-1:999999999:function2:alias",
"event_type": "origin-response",
"lambda_arn": "arn:aws:lambda:us-east-1:999999999:function2:alias",
"include_body": true,
},
}

Expand Down
15 changes: 15 additions & 0 deletions aws/resource_aws_cloudfront_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"include_body": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
Set: lambdaFunctionAssociationHash,
Expand Down Expand Up @@ -249,6 +254,11 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"include_body": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
Set: lambdaFunctionAssociationHash,
Expand Down Expand Up @@ -404,6 +414,11 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"include_body": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
Set: lambdaFunctionAssociationHash,
Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/cloudfront_distribution.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ resource "aws_cloudfront_distribution" "example" {
# ... other configuration ...
lambda_function_association {
event_type = "viewer-request"
lambda_arn = "${aws_lambda_function.example.qualified_arn}"
event_type = "viewer-request"
lambda_arn = "${aws_lambda_function.example.qualified_arn}"
include_body = false
}
}
}
Expand All @@ -305,6 +306,7 @@ resource "aws_cloudfront_distribution" "example" {
Valid values: `viewer-request`, `origin-request`, `viewer-response`,
`origin-response`
* `lambda_arn` (Required) - ARN of the Lambda function.
* `include_body` (Optional) - When set to true it exposes the request body to the lambda function. Defaults to false. Valid values: `true`, `false`.

##### Cookies Arguments

Expand Down

0 comments on commit 5228cd1

Please sign in to comment.