generated from DNXLabs/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwaf.tf
62 lines (51 loc) · 1.44 KB
/
waf.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
resource "aws_wafv2_ip_set" "ipset" {
count = var.wafv2_enable ? 1 : 0
name = "${var.name}-tfIPSet"
scope = "REGIONAL"
ip_address_version = "IPV4"
addresses = split(",", var.ip_allowlist)
}
resource "aws_wafv2_web_acl" "waf_apigateway" {
count = var.wafv2_enable ? 1 : 0
name = "${var.name}-waf_apigateway"
description = "WAF with ip whitelist rule"
scope = "REGIONAL"
default_action {
block {}
}
rule {
name = "ipwhitelist"
priority = 0
action {
allow {}
}
statement {
ip_set_reference_statement {
arn = aws_wafv2_ip_set.ipset[count.index].arn
ip_set_forwarded_ip_config {
fallback_behavior = "MATCH"
header_name = "SourceIP"
position = "FIRST"
}
}
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "waf-ipwhitelist"
sampled_requests_enabled = false
}
}
tags = {
Name = "${var.name}-waf_apigateway"
}
visibility_config {
cloudwatch_metrics_enabled = true
metric_name = "waf-general"
sampled_requests_enabled = false
}
}
resource "aws_wafv2_web_acl_association" "waf_alb_association" {
count = var.wafv2_enable ? 1 : 0
resource_arn = aws_api_gateway_stage.prod.arn
web_acl_arn = aws_wafv2_web_acl.waf_apigateway[count.index].arn
}