Sign in
Menu
Start free trial

AWS WAF v2 Terraform Module

Terraform module which creates AWS WAF v2 Web ACL resources with comprehensive rule support.

SWUbanner

Usage

module "wafv2" {
  source  = "terraform-aws-modules/wafv2/aws"

  name  = "my-web-acl"
  scope = "REGIONAL"

  default_action = "allow"

  rules = {
    common-rule-set = {
      priority        = 1
      override_action = "none"

      statement = {
        managed_rule_group_statement = {
          name        = "AWSManagedRulesCommonRuleSet"
          vendor_name = "AWS"
        }
      }
    }

    rate-limit = {
      priority = 2
      action   = "block"

      statement = {
        rate_based_statement = {
          limit = 1000
        }
      }
    }
  }

  tags = {
    Environment = "dev"
    Terraform   = "true"
  }
}

Features

  • Full coverage of AWS provider WAFv2 surface: every WAFv2 resource is supported by the root module or a submodule
  • AWS WAF v2 Web ACL with comprehensive rule statement support
  • All 12+ statement types: byte match, geo match, IP set reference, label match, managed rule group, rate based, regex match, regex pattern set reference, rule group reference, size constraint, SQLi match, XSS match
  • Compound statements (AND, OR, NOT) with 2 levels of nesting, including AND/OR inside scope_down_statement
  • Dual-mode actions: simple string ("allow", "block", "count", "captcha", "challenge") or objects with custom response/request handling
  • Custom response bodies
  • CAPTCHA and challenge configuration
  • Association configuration for request body size limits
  • Optional inline Web ACL associations
  • Optional inline logging configuration
  • Submodules for IP sets, regex pattern sets, Web ACL associations, logging configuration, custom rule groups, standalone Web ACL rules, Web ACL ↔ rule group associations, and CAPTCHA API keys

Conditional Creation

The module supports conditional resource creation:

module "wafv2" {
  source = "terraform-aws-modules/wafv2/aws"

  create = false
}

Submodules

Examples

Module Wrappers

For managing multiple similar resources, see wrappers.

Authors

Module is maintained by Anton Babenko with help from these awesome contributors.

License

Apache 2 Licensed. See LICENSE for full details.

Additional information for users from Russia and Belarus