restore lambdasethash, include in cache behavior id hash, and document (including limits)

This commit is contained in:
clint shryock 2017-01-19 15:53:52 -06:00
parent 5400f7c68e
commit 6d4f4007fe
4 changed files with 46 additions and 24 deletions

View File

@ -228,6 +228,12 @@ func defaultCacheBehaviorHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", e.(string)))
}
}
if d, ok := m["lambda_function_association"]; ok {
s := d.(*schema.Set)
for _, lfa := range s.List() {
buf.WriteString(fmt.Sprintf("%d-", lambdaFunctionAssociationHash(lfa.(map[string]interface{}))))
}
}
return hashcode.String(buf.String())
}
@ -360,6 +366,12 @@ func cacheBehaviorHash(v interface{}) int {
if d, ok := m["path_pattern"]; ok {
buf.WriteString(fmt.Sprintf("%s-", d))
}
if d, ok := m["lambda_function_association"]; ok {
s := d.(*schema.Set)
for _, lfa := range s.List() {
buf.WriteString(fmt.Sprintf("%d-", lambdaFunctionAssociationHash(lfa.(map[string]interface{}))))
}
}
return hashcode.String(buf.String())
}
@ -383,6 +395,14 @@ func flattenTrustedSigners(ts *cloudfront.TrustedSigners) []interface{} {
return []interface{}{}
}
func lambdaFunctionAssociationHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["event_type"].(string)))
buf.WriteString(fmt.Sprintf("%s", m["lambda_arn"].(string)))
return hashcode.String(buf.String())
}
func expandLambdaFunctionAssociations(v interface{}) *cloudfront.LambdaFunctionAssociations {
if v == nil {
return &cloudfront.LambdaFunctionAssociations{

View File

@ -1,14 +1,11 @@
package aws
import (
"bytes"
"fmt"
"reflect"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudfront"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
)
@ -49,18 +46,6 @@ func trustedSignersConf() []interface{} {
return []interface{}{"1234567890EX", "1234567891EX"}
}
func lambdaSetHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
if v, ok := m["event_type"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
if v, ok := m["lambda_arn"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))
}
return hashcode.String(buf.String())
}
func lambdaFunctionAssociationsConf() *schema.Set {
x := []interface{}{
map[string]interface{}{
@ -73,9 +58,7 @@ func lambdaFunctionAssociationsConf() *schema.Set {
},
}
s := schema.NewSet(lambdaSetHash, x)
return s
return schema.NewSet(lambdaFunctionAssociationHash, x)
}
func forwardedValuesConf() map[string]interface{} {
@ -270,6 +253,9 @@ func viewerCertificateConfSetACM() map[string]interface{} {
func TestCloudFrontStructure_expandDefaultCacheBehavior(t *testing.T) {
data := defaultCacheBehaviorConf()
dcb := expandDefaultCacheBehavior(data)
if dcb == nil {
t.Fatalf("ExpandDefaultCacheBehavior returned nil")
}
if *dcb.Compress != true {
t.Fatalf("Expected Compress to be true, got %v", *dcb.Compress)
}

View File

@ -118,6 +118,7 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
},
},
},
Set: lambdaFunctionAssociationHash,
},
"max_ttl": {
Type: schema.TypeInt,
@ -265,6 +266,7 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
},
},
},
Set: lambdaFunctionAssociationHash,
},
"max_ttl": {
Type: schema.TypeInt,

View File

@ -111,11 +111,9 @@ of several sub-resources - these resources are laid out below.
* `comment` (Optional) - Any comments you want to include about the
distribution.
* `custom_error_response` (Optional) - One or more [custom error
response](#custom-error-response-arguments) elements (multiples allowed).
* `custom_error_response` (Optional) - One or more [custom error response](#custom-error-response-arguments) elements (multiples allowed).
* `default_cache_behavior` (Required) - The [default cache
behavior](#default-cache-behavior-arguments) for this distribution (maximum
* `default_cache_behavior` (Required) - The [default cache behavior](#default-cache-behavior-arguments) for this distribution (maximum
one).
* `default_root_object` (Optional) - The object that you want CloudFront to
@ -173,10 +171,13 @@ of several sub-resources - these resources are laid out below.
object is in a CloudFront cache before CloudFront forwards another request
in the absence of an `Cache-Control max-age` or `Expires` header.
* `forwarded_values` (Required) - The [forwarded values
configuration](#forwarded-values-arguments) that specifies how CloudFront
* `forwarded_values` (Required) - The [forwarded values configuration](#forwarded-values-arguments) that specifies how CloudFront
handles query strings, cookies and headers (maximum one).
* `lambda_function_association` (Optional) - A complext config that triggers a lambda function with
specific actions. Defined below, maximum 4. **Lambda@Edge is in technical
Preview, and must be enabled on your AWS account to be used**
* `max_ttl` (Required) - The maximum amount of time (in seconds) that an
object is in a CloudFront cache before CloudFront forwards another request
to your origin to determine whether the object has been updated. Only
@ -222,6 +223,19 @@ of several sub-resources - these resources are laid out below.
`true` for `query_string`, all query strings are forwarded, however only the
query string keys listed in this argument are cached. When omitted with a
value of `true` for `query_string`, all query string keys are cached.
##### Lambda Function Association
Lambda@Edge allows you to associate an AWS Lambda Function with a predefined
event. You can associate a single function per event type. See [What is
Lambda@Edge](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/what-is-lambda-at-edge.html)
for more information
* `event_type` (Required) - The specific event to trigger this functionon.
Valid values: `viewwer-request`, `origin-request`, `viewer-response`,
`origin-response`
* `lambda_function_arn` (Required) - ARN of the Lambda function.
##### Cookies Arguments