Skip to content
Open
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
3 changes: 3 additions & 0 deletions .changelog/47409.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_wafv2_web_acl_logging_configuration: Fix `redacted_fields` removal not being detected
```
8 changes: 8 additions & 0 deletions internal/service/wafv2/web_acl_logging_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,14 @@ func redactedFieldsHash(v any) int {
}

func suppressRedactedFieldsDiff(k, old, new string, d *schema.ResourceData) bool {
// Detect full removal via raw parameters: d.GetChange() can return stale
// "new" data for nested TypeList attributes, causing the Set comparison
// below to miss the diff.
// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/41778
if k == "redacted_fields.#" && old != "0" && new == "0" {
return false
}

o, n := d.GetChange("redacted_fields")
oList := o.([]any)
nList := n.([]any)
Expand Down
44 changes: 44 additions & 0 deletions internal/service/wafv2/web_acl_logging_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,50 @@ func TestAccWAFV2WebACLLoggingConfiguration_updateEmptyRedactedFields(t *testing
})
}

// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/41778
func TestAccWAFV2WebACLLoggingConfiguration_removeRedactedFields(t *testing.T) {
ctx := acctest.Context(t)
var v awstypes.LoggingConfiguration
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
resourceName := "aws_wafv2_web_acl_logging_configuration.test"
webACLResourceName := "aws_wafv2_web_acl.test"

acctest.ParallelTest(ctx, t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.WAFV2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckWebACLLoggingConfigurationDestroy(ctx, t),
Steps: []resource.TestStep{
{
Config: testAccWebACLLoggingConfigurationConfig_updateSingleHeaderRedactedField(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckWebACLLoggingConfigurationExists(ctx, t, resourceName, &v),
resource.TestCheckResourceAttrPair(resourceName, names.AttrResourceARN, webACLResourceName, names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "log_destination_configs.#", "1"),
resource.TestCheckResourceAttr(resourceName, "redacted_fields.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "redacted_fields.*", map[string]string{
"single_header.0.name": "user-agent",
}),
),
},
{
Config: testAccWebACLLoggingConfigurationConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckWebACLLoggingConfigurationExists(ctx, t, resourceName, &v),
resource.TestCheckResourceAttrPair(resourceName, names.AttrResourceARN, webACLResourceName, names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "log_destination_configs.#", "1"),
resource.TestCheckResourceAttr(resourceName, "redacted_fields.#", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccWAFV2WebACLLoggingConfiguration_Disappears_webACL(t *testing.T) {
ctx := acctest.Context(t)
var v awstypes.LoggingConfiguration
Expand Down