From e24597888e04e29864b2f3cfdb4fa6f9433c075e Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 23 Jun 2017 11:50:42 +0100 Subject: [PATCH] resource/waf: Only set FieldToMatch.Data if not empty --- aws/resource_aws_waf_byte_match_set.go | 18 --------------- ...resource_aws_wafregional_byte_match_set.go | 14 ------------ aws/structure.go | 22 +++++++++++++++++++ 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/aws/resource_aws_waf_byte_match_set.go b/aws/resource_aws_waf_byte_match_set.go index 53f3e93b825..c215522a7ad 100644 --- a/aws/resource_aws_waf_byte_match_set.go +++ b/aws/resource_aws_waf_byte_match_set.go @@ -192,24 +192,6 @@ func flattenWafByteMatchTuples(bmt []*waf.ByteMatchTuple) []interface{} { return out } -func expandFieldToMatch(d map[string]interface{}) *waf.FieldToMatch { - return &waf.FieldToMatch{ - Type: aws.String(d["type"].(string)), - Data: aws.String(d["data"].(string)), - } -} - -func flattenFieldToMatch(fm *waf.FieldToMatch) []interface{} { - m := make(map[string]interface{}) - if fm.Data != nil { - m["data"] = *fm.Data - } - if fm.Type != nil { - m["type"] = *fm.Type - } - return []interface{}{m} -} - func diffWafByteMatchSetTuples(oldT, newT []interface{}) []*waf.ByteMatchSetUpdate { updates := make([]*waf.ByteMatchSetUpdate, 0) diff --git a/aws/resource_aws_wafregional_byte_match_set.go b/aws/resource_aws_wafregional_byte_match_set.go index d7f916ad36b..f2b849803cf 100644 --- a/aws/resource_aws_wafregional_byte_match_set.go +++ b/aws/resource_aws_wafregional_byte_match_set.go @@ -213,20 +213,6 @@ func updateByteMatchSetResourceWR(d *schema.ResourceData, oldT, newT []interface return nil } -func expandFieldToMatchWR(d map[string]interface{}) *waf.FieldToMatch { - return &waf.FieldToMatch{ - Type: aws.String(d["type"].(string)), - Data: aws.String(d["data"].(string)), - } -} - -func flattenFieldToMatchWR(fm *waf.FieldToMatch) map[string]interface{} { - m := make(map[string]interface{}) - m["data"] = *fm.Data - m["type"] = *fm.Type - return m -} - func diffByteMatchSetTuple(oldT, newT []interface{}) []*waf.ByteMatchSetUpdate { updates := make([]*waf.ByteMatchSetUpdate, 0) diff --git a/aws/structure.go b/aws/structure.go index 262dccfdc7b..a4ab3d022ac 100644 --- a/aws/structure.go +++ b/aws/structure.go @@ -29,6 +29,7 @@ import ( "github.com/aws/aws-sdk-go/service/redshift" "github.com/aws/aws-sdk-go/service/route53" "github.com/aws/aws-sdk-go/service/ssm" + "github.com/aws/aws-sdk-go/service/waf" "github.com/hashicorp/terraform/helper/schema" "gopkg.in/yaml.v2" ) @@ -2125,3 +2126,24 @@ func flattenAwsSsmTargets(targets []*ssm.Target) []map[string]interface{} { return result } + +func expandFieldToMatch(d map[string]interface{}) *waf.FieldToMatch { + ftm := &waf.FieldToMatch{ + Type: aws.String(d["type"].(string)), + } + if data, ok := d["data"].(string); ok && data != "" { + ftm.Data = aws.String(data) + } + return ftm +} + +func flattenFieldToMatch(fm *waf.FieldToMatch) []interface{} { + m := make(map[string]interface{}) + if fm.Data != nil { + m["data"] = *fm.Data + } + if fm.Type != nil { + m["type"] = *fm.Type + } + return []interface{}{m} +}