🖥

AWS Terraform - WAF で基本はアクセスをブロック、指定のIPアドレスだけを許可する例

に公開

resource "aws_wafv2_web_acl" "example" {
  name  = "example-waf-acl-name"
  scope = "REGIONAL"

  default_action {
    block {}
  }

  # 設定はてきとう
  visibility_config {
    cloudwatch_metrics_enabled = false
    metric_name                = "example-waf-metric"
    sampled_requests_enabled   = false
  }

  rule {
    name     = "allow-ips-list"
    priority = 1

    action {
      allow {
      }
    }

    statement {
      or_statement {
        statement {
          ip_set_reference_statement {
            arn = <WAFのIPセットのARN>
          }
        }
        statement {
          ip_set_reference_statement {
            arn = <WAFのIPセットのARN>
          }
        }
      }
    }

    # 設定はてきとう
    visibility_config {
      cloudwatch_metrics_enabled = false
      metric_name                = "example-waf-rule-metric"
      sampled_requests_enabled   = false
    }
  }
}

参考

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

プロフィール・経歴

https://github.com/YumaInaura/YumaInaura

公開日時

2025-03-28

https://qiita.com/YumaInaura/items/d79a6e68bc1c2e9c26b6

Discussion