Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the difference between aws_waf_byte_match_set and aws_wafregional_byte_match_set #5043

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions aws/resource_aws_wafregional_byte_match_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,45 @@ func resourceAwsWafRegionalByteMatchSet() *schema.Resource {
ForceNew: true,
},
"byte_match_tuple": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"byte_match_tuples"},
Deprecated: "use `byte_match_tuples` instead",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"field_to_match": {
Type: schema.TypeSet,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data": {
Type: schema.TypeString,
Optional: true,
},
"type": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"positional_constraint": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"target_string": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"text_transformation": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
},
},
"byte_match_tuples": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -110,7 +149,11 @@ func resourceAwsWafRegionalByteMatchSetRead(d *schema.ResourceData, meta interfa
return err
}

d.Set("byte_match_tuple", flattenWafByteMatchTuplesWR(resp.ByteMatchSet.ByteMatchTuples))
if _, ok := d.GetOk("byte_match_tuple"); ok {
d.Set("byte_match_tuple", flattenWafByteMatchTuplesWR(resp.ByteMatchSet.ByteMatchTuples))
} else {
d.Set("byte_match_tuples", flattenWafByteMatchTuplesWR(resp.ByteMatchSet.ByteMatchTuples))
}
d.Set("name", resp.ByteMatchSet.Name)

return nil
Expand Down Expand Up @@ -155,6 +198,14 @@ func resourceAwsWafRegionalByteMatchSetUpdate(d *schema.ResourceData, meta inter
o, n := d.GetChange("byte_match_tuple")
oldT, newT := o.(*schema.Set).List(), n.(*schema.Set).List()

err := updateByteMatchSetResourceWR(d, oldT, newT, conn, region)
if err != nil {
return errwrap.Wrapf("[ERROR] Error updating ByteMatchSet: {{err}}", err)
}
} else if d.HasChange("byte_match_tuples") {
o, n := d.GetChange("byte_match_tuples")
oldT, newT := o.(*schema.Set).List(), n.(*schema.Set).List()

err := updateByteMatchSetResourceWR(d, oldT, newT, conn, region)
if err != nil {
return errwrap.Wrapf("[ERROR] Error updating ByteMatchSet: {{err}}", err)
Expand All @@ -169,7 +220,12 @@ func resourceAwsWafRegionalByteMatchSetDelete(d *schema.ResourceData, meta inter

log.Printf("[INFO] Deleting ByteMatchSet: %s", d.Get("name").(string))

oldT := d.Get("byte_match_tuple").(*schema.Set).List()
var oldT []interface{}
if _, ok := d.GetOk("byte_match_tuple"); ok {
oldT = d.Get("byte_match_tuple").(*schema.Set).List()
} else {
oldT = d.Get("byte_match_tuples").(*schema.Set).List()
}

if len(oldT) > 0 {
var newT []interface{}
Expand Down
Loading