我设法使用Terraform脚本在AWS上构建了WAF(v1)基础架构组件。自2019年11月以来,AWS建议改用WAFv2,但我看不到如何使用Terraform编写脚本。
答案 0 :(得分:2)
当然,这是WAFv2的资源示例,其中包含速率限制示例规则以及与ALB的关联:
resource "aws_wafv2_web_acl" "my_web_acl" {
name = "my-web-acl"
scope = "REGIONAL"
default_action {
allow {}
}
rule {
name = "RateLimit"
priority = 1
action {
block {}
}
statement {
rate_based_statement {
aggregate_key_type = "IP"
limit = 500
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "RateLimit"
sampled_requests_enabled = true
}
}
visibility_config {
cloudwatch_metrics_enabled = false
metric_name = "my-web-acl"
sampled_requests_enabled = false
}
}
resource "aws_wafv2_web_acl_association" "web_acl_association_my_lb" {
resource_arn = aws_lb.my_lb.arn
web_acl_arn = aws_wafv2_web_acl.my_web_acl.arn
}
答案 1 :(得分:1)
terraform尚不支持此功能。但是,如果您真的想使用terraform,我已经构建了一个模块,该模块使用cloudformation资源来部署wafv2。您可以找到它-> https://github.com/umotif-public/terraform-aws-waf-webaclv2
它已发布到terraform注册中心,因此您可以从那里获取它。