From 2c21f1548536542aed8d70e3b507ec62e827057f Mon Sep 17 00:00:00 2001 From: parabolic Date: Sun, 26 Aug 2018 12:22:08 +0200 Subject: [PATCH 1/4] add the include_body option to the resouce and set it to false as default as it is with the api --- aws/resource_aws_cloudfront_distribution.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/aws/resource_aws_cloudfront_distribution.go b/aws/resource_aws_cloudfront_distribution.go index 640fe06ba3c..bf72d8055d1 100644 --- a/aws/resource_aws_cloudfront_distribution.go +++ b/aws/resource_aws_cloudfront_distribution.go @@ -124,6 +124,11 @@ func resourceAwsCloudFrontDistribution() *schema.Resource { Type: schema.TypeString, Required: true, }, + "include_body": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, }, Set: lambdaFunctionAssociationHash, @@ -249,6 +254,11 @@ func resourceAwsCloudFrontDistribution() *schema.Resource { Type: schema.TypeString, Required: true, }, + "include_body": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, }, Set: lambdaFunctionAssociationHash, @@ -404,6 +414,11 @@ func resourceAwsCloudFrontDistribution() *schema.Resource { Type: schema.TypeString, Required: true, }, + "include_body": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, }, Set: lambdaFunctionAssociationHash, From 6bbf7f904cfd3a45febe43031f9dcfa26504787d Mon Sep 17 00:00:00 2001 From: parabolic Date: Sun, 26 Aug 2018 12:22:53 +0200 Subject: [PATCH 2/4] add the option to the configuration structure --- aws/cloudfront_distribution_configuration_structure.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aws/cloudfront_distribution_configuration_structure.go b/aws/cloudfront_distribution_configuration_structure.go index 55bdd3509d5..013f5508ff3 100644 --- a/aws/cloudfront_distribution_configuration_structure.go +++ b/aws/cloudfront_distribution_configuration_structure.go @@ -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()) } @@ -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 } @@ -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 } From 650f79bc6f28c2cc27cf5a4eb0298cc0bceca57a Mon Sep 17 00:00:00 2001 From: parabolic Date: Sun, 26 Aug 2018 12:23:00 +0200 Subject: [PATCH 3/4] adjust the tests for the include_body option --- ...dfront_distribution_configuration_structure_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/aws/cloudfront_distribution_configuration_structure_test.go b/aws/cloudfront_distribution_configuration_structure_test.go index 12ed2b1b075..8919e376a94 100644 --- a/aws/cloudfront_distribution_configuration_structure_test.go +++ b/aws/cloudfront_distribution_configuration_structure_test.go @@ -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, }, } From 855a1aacbd4aa05b913983707f94eadd40734d9e Mon Sep 17 00:00:00 2001 From: parabolic Date: Mon, 27 Aug 2018 10:46:29 +0200 Subject: [PATCH 4/4] add documentation for the include_body option --- website/docs/r/cloudfront_distribution.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website/docs/r/cloudfront_distribution.html.markdown b/website/docs/r/cloudfront_distribution.html.markdown index cb42a143fac..2d658d0ae15 100644 --- a/website/docs/r/cloudfront_distribution.html.markdown +++ b/website/docs/r/cloudfront_distribution.html.markdown @@ -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 } } } @@ -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