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

Add include body for lambda function association #5681

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
5 changes: 5 additions & 0 deletions aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,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 @@ -554,6 +555,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 @@ -570,6 +574,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