Skip to content

Commit

Permalink
Merge pull request #953 from terraform-providers/b-aws-waf-optional-f…
Browse files Browse the repository at this point in the history
…tm-data

resource/waf: Only set FieldToMatch.Data if not empty
  • Loading branch information
radeksimko authored Jun 23, 2017
2 parents 376ea9b + e245978 commit 20d6ae4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
18 changes: 0 additions & 18 deletions aws/resource_aws_waf_byte_match_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 0 additions & 14 deletions aws/resource_aws_wafregional_byte_match_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 22 additions & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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}
}

0 comments on commit 20d6ae4

Please sign in to comment.