lambda_function_association attribute as []interface{}

This commit is contained in:
Tim Gossett 2017-01-06 10:20:35 -05:00
parent 9c5a25dd48
commit 32f7a86e10
No known key found for this signature in database
GPG Key ID: 6708169C08D3CCF0
3 changed files with 12 additions and 33 deletions

View File

@ -228,11 +228,6 @@ func defaultCacheBehaviorHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", e.(string))) buf.WriteString(fmt.Sprintf("%s-", e.(string)))
} }
} }
if d, ok := m["lambda_function_association"]; ok {
for _, e := range d.(*schema.Set).List() {
buf.WriteString(fmt.Sprintf("%d-", lambdaFunctionAssociationHash(e.(map[string]interface{}))))
}
}
return hashcode.String(buf.String()) return hashcode.String(buf.String())
} }
@ -365,11 +360,6 @@ func cacheBehaviorHash(v interface{}) int {
if d, ok := m["path_pattern"]; ok { if d, ok := m["path_pattern"]; ok {
buf.WriteString(fmt.Sprintf("%s-", d)) buf.WriteString(fmt.Sprintf("%s-", d))
} }
if d, ok := m["lambda_function_association"]; ok {
for _, e := range d.(*schema.Set).List() {
buf.WriteString(fmt.Sprintf("%d-", lambdaFunctionAssociationHash(e.(map[string]interface{}))))
}
}
return hashcode.String(buf.String()) return hashcode.String(buf.String())
} }
@ -400,11 +390,11 @@ func expandLambdaFunctionAssociations(v interface{}) *cloudfront.LambdaFunctionA
} }
} }
s := v.(*schema.Set) s := v.([]interface{})
var lfa cloudfront.LambdaFunctionAssociations var lfa cloudfront.LambdaFunctionAssociations
lfa.Quantity = aws.Int64(int64(s.Len())) lfa.Quantity = aws.Int64(int64(len(s)))
lfa.Items = make([]*cloudfront.LambdaFunctionAssociation, s.Len()) lfa.Items = make([]*cloudfront.LambdaFunctionAssociation, len(s))
for i, lf := range s.List() { for i, lf := range s {
lfa.Items[i] = expandLambdaFunctionAssociation(lf.(map[string]interface{})) lfa.Items[i] = expandLambdaFunctionAssociation(lf.(map[string]interface{}))
} }
return &lfa return &lfa
@ -421,12 +411,12 @@ func expandLambdaFunctionAssociation(lf map[string]interface{}) *cloudfront.Lamb
return &lfa return &lfa
} }
func flattenLambdaFunctionAssociations(lfa *cloudfront.LambdaFunctionAssociations) *schema.Set { func flattenLambdaFunctionAssociations(lfa *cloudfront.LambdaFunctionAssociations) []interface{} {
s := make([]interface{}, len(lfa.Items)) s := make([]interface{}, len(lfa.Items))
for i, v := range lfa.Items { for i, v := range lfa.Items {
s[i] = flattenLambdaFunctionAssociation(v) s[i] = flattenLambdaFunctionAssociation(v)
} }
return schema.NewSet(lambdaFunctionAssociationHash, s) return s
} }
func flattenLambdaFunctionAssociation(lfa *cloudfront.LambdaFunctionAssociation) map[string]interface{} { func flattenLambdaFunctionAssociation(lfa *cloudfront.LambdaFunctionAssociation) map[string]interface{} {
@ -438,14 +428,6 @@ func flattenLambdaFunctionAssociation(lfa *cloudfront.LambdaFunctionAssociation)
return m return m
} }
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 expandForwardedValues(m map[string]interface{}) *cloudfront.ForwardedValues { func expandForwardedValues(m map[string]interface{}) *cloudfront.ForwardedValues {
fv := &cloudfront.ForwardedValues{ fv := &cloudfront.ForwardedValues{
QueryString: aws.Bool(m["query_string"].(bool)), QueryString: aws.Bool(m["query_string"].(bool)),

View File

@ -46,7 +46,7 @@ func trustedSignersConf() []interface{} {
return []interface{}{"1234567890EX", "1234567891EX"} return []interface{}{"1234567890EX", "1234567891EX"}
} }
func lambdaFunctionAssociationsConf() *schema.Set { func lambdaFunctionAssociationsConf() []interface{} {
s := []interface{}{ s := []interface{}{
map[string]interface{}{ map[string]interface{}{
"event_type": "viewer-request", "event_type": "viewer-request",
@ -57,7 +57,7 @@ func lambdaFunctionAssociationsConf() *schema.Set {
"lambda_arn": "arn:aws:lambda:us-east-1:999999999:function2:alias", "lambda_arn": "arn:aws:lambda:us-east-1:999999999:function2:alias",
}, },
} }
return schema.NewSet(lambdaFunctionAssociationHash, s) return s
} }
func forwardedValuesConf() map[string]interface{} { func forwardedValuesConf() map[string]interface{} {
@ -359,9 +359,8 @@ func TestCloudFrontStructure_flattenCacheBehavior(t *testing.T) {
if out["target_origin_id"] != "myS3Origin" { if out["target_origin_id"] != "myS3Origin" {
t.Fatalf("Expected out[target_origin_id] to be myS3Origin, got %v", out["target_origin_id"]) t.Fatalf("Expected out[target_origin_id] to be myS3Origin, got %v", out["target_origin_id"])
} }
diff = out["lambda_function_association"].(*schema.Set).Difference(in["lambda_function_association"].(*schema.Set)) if reflect.DeepEqual(out["lambda_function_associations"], in["lambda_function_associations"]) != true {
if diff.Len() > 0 { t.Fatalf("Expected out[lambda_function_associations] to be %v, got %v", in["lambda_function_associations"], out["lambda_function_associations"])
t.Fatalf("Expected out[lambda_function_association] to be %v, got %v, diff: %v", out["lambda_function_association"], in["lambda_function_association"], diff)
} }
diff = out["forwarded_values"].(*schema.Set).Difference(in["forwarded_values"].(*schema.Set)) diff = out["forwarded_values"].(*schema.Set).Difference(in["forwarded_values"].(*schema.Set))
if len(diff.List()) > 0 { if len(diff.List()) > 0 {
@ -475,13 +474,13 @@ func TestCloudFrontStructure_flattenlambdaFunctionAssociations(t *testing.T) {
lfa := expandLambdaFunctionAssociations(in) lfa := expandLambdaFunctionAssociations(in)
out := flattenLambdaFunctionAssociations(lfa) out := flattenLambdaFunctionAssociations(lfa)
if out.Difference(in).Len() != 0 { if reflect.DeepEqual(in, out) != true {
t.Fatalf("Expected out to be %v, got %v", in, out) t.Fatalf("Expected out to be %v, got %v", in, out)
} }
} }
func TestCloudFrontStructure_expandlambdaFunctionAssociations_empty(t *testing.T) { func TestCloudFrontStructure_expandlambdaFunctionAssociations_empty(t *testing.T) {
data := schema.NewSet(lambdaFunctionAssociationHash, []interface{}{}) data := []interface{}{}
lfa := expandLambdaFunctionAssociations(data) lfa := expandLambdaFunctionAssociations(data)
if *lfa.Quantity != 0 { if *lfa.Quantity != 0 {
t.Fatalf("Expected Quantity to be 0, got %v", *lfa.Quantity) t.Fatalf("Expected Quantity to be 0, got %v", *lfa.Quantity)

View File

@ -105,7 +105,6 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
"lambda_function_association": { "lambda_function_association": {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Set: lambdaFunctionAssociationHash,
MaxItems: 4, MaxItems: 4,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -253,7 +252,6 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
"lambda_function_association": { "lambda_function_association": {
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Set: lambdaFunctionAssociationHash,
MaxItems: 4, MaxItems: 4,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{