Skip to content

Commit

Permalink
mark update field suppress func needed
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Dec 3, 2020
1 parent 7fe9efd commit c3fdbfb
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions aws/resource_aws_wafv2_web_acl_logging_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package aws
import (
"bytes"
"fmt"
"log"
"regexp"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/wafv2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/hashcode"
"log"
"regexp"
)

func resourceAwsWafv2WebACLLoggingConfiguration() *schema.Resource {
Expand Down Expand Up @@ -41,33 +42,10 @@ func resourceAwsWafv2WebACLLoggingConfiguration() *schema.Resource {
// to be correctly interpreted, this argument must be of type List,
// otherwise, at apply-time a field configured as an empty block
// (e.g. body {}) will result in a nil redacted_fields attribute
Type: schema.TypeList,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
o, n := d.GetChange("redacted_fields")
oList := o.([]interface{})
nList := n.([]interface{})
if len(oList) == 0 && len(nList) == 0 {
return true
}
if len(oList) == 0 && len(nList) != 0 {
if nList[0] == nil {
return true
}
return false
}
if len(oList) != 0 && len(nList) == 0 {
if oList[0] == nil {
return true
}
return false
}

oldSet := schema.NewSet(redactedFieldsHash, oList)
newSet := schema.NewSet(redactedFieldsHash, nList)
return oldSet.Equal(newSet)
},
MaxItems: 100,
Type: schema.TypeList,
Optional: true,
DiffSuppressFunc: suppressRedactedFieldsDiff,
MaxItems: 100,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// TODO: remove attributes marked as Deprecated
Expand Down Expand Up @@ -309,3 +287,27 @@ func redactedFieldsHash(v interface{}) int {

return hashcode.String(buf.String())
}

func suppressRedactedFieldsDiff(k, old, new string, d *schema.ResourceData) bool {
o, n := d.GetChange("redacted_fields")
oList := o.([]interface{})
nList := n.([]interface{})

if len(oList) == 0 && len(nList) == 0 {
return true
}

if len(oList) == 0 && len(nList) != 0 {
// account for empty block
return nList[0] == nil
}

if len(oList) != 0 && len(nList) == 0 {
// account for empty block
return oList[0] == nil
}

oldSet := schema.NewSet(redactedFieldsHash, oList)
newSet := schema.NewSet(redactedFieldsHash, nList)
return oldSet.Equal(newSet)
}

0 comments on commit c3fdbfb

Please sign in to comment.