【发布时间】:2020-12-14 21:24:28
【问题描述】:
我使用 AWS 控制台创建了 WAF ACL。现在我需要使用 Terraform 创建 WAF 规则,所以我实现了以下规则。
resource "aws_wafregional_byte_match_set" "blocked_path_match_set" {
name = format("%s-%s-blocked-path", local.name, var.module)
dynamic "byte_match_tuples" {
for_each = length(var.blocked_path_prefixes) > 0 ? var.blocked_path_prefixes : []
content {
field_to_match {
type = lookup(byte_match_tuples.value, "type", null)
}
target_string = lookup(byte_match_tuples.value, "target_string", null)
positional_constraint = lookup(byte_match_tuples.value, "positional_constraint", null)
text_transformation = lookup(byte_match_tuples.value, "text_transformation", null)
}
}
}
resource "aws_wafregional_rule" "blocked_path_allowed_ipaccess" {
metric_name = format("%s%s%sBlockedPathIpaccess", var.application, var.environment, var.module)
name = format("%s%s%sBlockedPathIpaccessRule", var.application, var.environment, var.module)
predicate {
type = "ByteMatch"
data_id = aws_wafregional_byte_match_set.blocked_path_match_set.id
negated = false
}
}
但是我如何将此新规则映射到通过 AWS 控制台创建的现有“web_acl”。根据文档,我可以使用“aws_wafregional_web_acl”来创建新的 web_acl,但是有没有办法将通过 terraform 创建的规则与现有的 waf_acl 相关联?我有一个 gitlab 管道,它将 terraform 代码部署到 aws,所以最终我将传递现有 web_acl 的 id/arn 并通过管道添加/更新新规则,而不会影响通过控制台创建的现有规则。
请分享您的宝贵意见。
谢谢。
【问题讨论】:
标签: amazon-web-services terraform terraform-provider-aws amazon-waf