Skip to content

Commit

Permalink
resources/wafregional_web_acl: add rule type test
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwltr committed Jun 25, 2018
1 parent 970a6c9 commit 7f4e184
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions aws/resource_aws_wafregional_web_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ func TestAccAWSWafRegionalWebAcl_basic(t *testing.T) {
})
}

func TestAccAWSWafRegionalWebAcl_createRateBased(t *testing.T) {
var v waf.WebACL
wafAclName := fmt.Sprintf("wafacl%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSWafRegionalWebAclDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSWafRegionalWebAclConfigRateBased(wafAclName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafRegionalWebAclExists("aws_wafregional_web_acl.waf_acl", &v),
resource.TestCheckResourceAttr(
"aws_wafregional_web_acl.waf_acl", "default_action.#", "1"),
resource.TestCheckResourceAttr(
"aws_wafregional_web_acl.waf_acl", "default_action.0.type", "ALLOW"),
resource.TestCheckResourceAttr(
"aws_wafregional_web_acl.waf_acl", "name", wafAclName),
resource.TestCheckResourceAttr(
"aws_wafregional_web_acl.waf_acl", "rule.#", "1"),
resource.TestCheckResourceAttr(
"aws_wafregional_web_acl.waf_acl", "metric_name", wafAclName),
),
},
},
})
}

func TestAccAWSWafRegionalWebAcl_changeNameForceNew(t *testing.T) {
var before, after waf.WebACL
wafAclName := fmt.Sprintf("wafacl%s", acctest.RandString(5))
Expand Down Expand Up @@ -374,6 +403,34 @@ resource "aws_wafregional_web_acl" "waf_acl" {
}`, name, name, name, name)
}

func testAccAWSWafRegionalWebAclConfigRateBased(name string) string {
return fmt.Sprintf(`
resource "aws_wafregional_rate_based_rule" "wafrule" {
name = "%s"
metric_name = "%s"
rate_key = "IP"
rate_limit = 2000
}
resource "aws_wafregional_web_acl" "waf_acl" {
name = "%s"
metric_name = "%s"
default_action {
type = "ALLOW"
}
rule {
action {
type = "BLOCK"
}
priority = 1
type = "RATE_BASED"
rule_id = "${aws_wafregional_rate_based_rule.wafrule.id}"
}
}`, name, name, name, name)
}

func testAccAWSWafRegionalWebAclConfig_changeName(name string) string {
return fmt.Sprintf(`
resource "aws_wafregional_rule" "wafrule" {
Expand Down

0 comments on commit 7f4e184

Please sign in to comment.