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

View File

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

View File

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