title: Dynamically create multiple WAF rules with Terraform
body: <p>I've got a piece of Terraform code that creates a Web ACL with a set of rules in AWS.</p>
  <pre><code>provider &quot;aws&quot; {
    region = &quot;eu-west-2&quot;
  }
  
  resource &quot;aws_wafv2_web_acl&quot; &quot;foo&quot; {
      name        = &quot;foo&quot;
      description = &quot;foo&quot;
      scope       = &quot;REGIONAL&quot;
      default_action {
          block {}
      }
      rule {
        name = &quot;AWS-AWSManagedRulesLinuxRuleSet&quot;
        priority = 0
        override_action {
          count {}
        }
        statement {
          managed_rule_group_statement {
            name = &quot;AWS-AWSManagedRulesLinuxRuleSet&quot;
            vendor_name = &quot;AWS&quot;
          }
        }
        visibility_config {
          cloudwatch_metrics_enabled = false 
          metric_name                 = &quot;foo_name&quot;
          sampled_requests_enabled   = false
        }
      }
      rule {
        name = &quot;AWS-AWSManagedRulesSQLiRuleSet&quot;
        priority = 1
        override_action {
          count {}
        }
        statement {
          managed_rule_group_statement {
            name = &quot;AWS-AWSManagedRulesSQLiRuleSet&quot;
            vendor_name = &quot;AWS&quot;
          }
        }
        visibility_config {
          cloudwatch_metrics_enabled = false
          metric_name                = &quot;foo_name&quot;
          sampled_requests_enabled   = false
        }
      }
      tags = {
        Tag1 = &quot;Value1&quot;
      }
      visibility_config {
        metric_name = &quot;foo&quot;
        sampled_requests_enabled = false
        cloudwatch_metrics_enabled = false
      }   
  }
  </code></pre>
  <p>This works fine, but adding more rules means that my code starts to turn into somewhat of a monolith.</p>
  <p>Is there a way to create multiple rules in Terraform using <code>dynamic_blocks</code> or <code>for_each</code> or something else, in a way that looks cleaner and dry?</p>