Skip to content

Commit

Permalink
add AssociationConfig update test
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocharpineljr committed Jul 4, 2023
1 parent 9eab657 commit 6065283
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 26 deletions.
4 changes: 2 additions & 2 deletions internal/service/wafv2/web_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ func resourceWebACLUpdate(ctx context.Context, d *schema.ResourceData, meta inte
VisibilityConfig: expandVisibilityConfig(d.Get("visibility_config").([]interface{})),
}

if v, ok := d.GetOk("association_config"); ok && v.(*schema.Set).Len() > 0 {
input.AssociationConfig = expandAssociationConfig(v.(*schema.Set).List())
if v, ok := d.GetOk("association_config"); ok {
input.AssociationConfig = expandAssociationConfig(v.([]interface{}))
}

if v, ok := d.GetOk("custom_response_body"); ok && v.(*schema.Set).Len() > 0 {
Expand Down
121 changes: 97 additions & 24 deletions internal/service/wafv2/web_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2435,31 +2435,57 @@ func TestAccWAFV2WebACL_AssociationConfig(t *testing.T) {
})
}

func testAccWebACLConfig_associationConfig(name string) string {
return fmt.Sprintf(`
resource "aws_wafv2_web_acl" "test" {
name = %[1]q
description = %[1]q
scope = "CLOUDFRONT"
default_action {
allow {}
}
visibility_config {
cloudwatch_metrics_enabled = false
metric_name = "friendly-metric-name"
sampled_requests_enabled = false
}
func TestAccWAFV2WebACL_AssociationConfig_Update(t *testing.T) {
ctx := acctest.Context(t)
var v wafv2.WebACL
webACLName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_wafv2_web_acl.test"

association_config {
request_body {
key = "CLOUDFRONT"
default_size_inspection_limit = "KB_32"
}
}
}
`, name)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckRegion(t, "us-east-1")
acctest.PreCheckPartitionHasService(t, wafv2.EndpointsID)
acctest.PreCheckPartitionHasService(t, cloudfront.EndpointsID)
testAccPreCheckScopeCloudfront(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, wafv2.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckWebACLDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccWebACLConfig_basicCloudFront(webACLName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckWebACLExists(ctx, resourceName, &v),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "wafv2", regexp.MustCompile(`global/webacl/.+$`)),
resource.TestCheckResourceAttr(resourceName, "name", webACLName),
resource.TestCheckResourceAttr(resourceName, "scope", "CLOUDFRONT"),
resource.TestCheckResourceAttr(resourceName, "description", webACLName),
resource.TestCheckResourceAttr(resourceName, "association_config.#", "0"),
),
},
{
Config: testAccWebACLConfig_associationConfig(webACLName),
Check: resource.ComposeTestCheckFunc(
testAccCheckWebACLExists(ctx, resourceName, &v),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "wafv2", regexp.MustCompile(`global/webacl/.+$`)),
resource.TestCheckResourceAttr(resourceName, "name", webACLName),
resource.TestCheckResourceAttr(resourceName, "scope", "CLOUDFRONT"),
resource.TestCheckResourceAttr(resourceName, "description", webACLName),
resource.TestCheckResourceAttr(resourceName, "association_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "association_config.0.request_body.#", "1"),
resource.TestCheckResourceAttr(resourceName, "association_config.0.request_body.0.key", "CLOUDFRONT"),
resource.TestCheckResourceAttr(resourceName, "association_config.0.request_body.0.default_size_inspection_limit", "KB_32"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccWebACLImportStateIdFunc(resourceName),
},
},
})
}

func testAccCheckWebACLDestroy(ctx context.Context) resource.TestCheckFunc {
Expand Down Expand Up @@ -2513,6 +2539,33 @@ func testAccCheckWebACLExists(ctx context.Context, n string, v *wafv2.WebACL) re
}
}

func testAccWebACLConfig_associationConfig(name string) string {
return fmt.Sprintf(`
resource "aws_wafv2_web_acl" "test" {
name = %[1]q
description = %[1]q
scope = "CLOUDFRONT"
default_action {
allow {}
}
visibility_config {
cloudwatch_metrics_enabled = false
metric_name = "friendly-metric-name"
sampled_requests_enabled = false
}
association_config {
request_body {
key = "CLOUDFRONT"
default_size_inspection_limit = "KB_32"
}
}
}
`, name)
}

func testAccWebACLConfig_basic(name string) string {
return fmt.Sprintf(`
resource "aws_wafv2_web_acl" "test" {
Expand All @@ -2533,6 +2586,26 @@ resource "aws_wafv2_web_acl" "test" {
`, name)
}

func testAccWebACLConfig_basicCloudFront(name string) string {
return fmt.Sprintf(`
resource "aws_wafv2_web_acl" "test" {
name = %[1]q
description = %[1]q
scope = "CLOUDFRONT"
default_action {
allow {}
}
visibility_config {
cloudwatch_metrics_enabled = false
metric_name = "friendly-metric-name"
sampled_requests_enabled = false
}
}
`, name)
}

func testAccWebACLConfig_basicRule(name string) string {
return fmt.Sprintf(`
resource "aws_wafv2_web_acl" "test" {
Expand Down

0 comments on commit 6065283

Please sign in to comment.