-
Notifications
You must be signed in to change notification settings - Fork 0
/
firewall_polices.tf
173 lines (170 loc) · 4.61 KB
/
firewall_polices.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
locals {
default_rules = [
{
priority = 400
direction = "INGRESS"
action = "allow"
rule_name = "allow-healthchecks"
disabled = false
description = "Allow healthchecks"
enable_logging = false
# target_secure_tags = ["l7-web-proxy"]
match = {
src_ip_ranges = ["35.191.0.0/16", "130.211.0.0/22"]
layer4_configs = [
{
ip_protocol = "tcp"
ports = ["3128"]
}
]
}
},
{
priority = 410
direction = "EGRESS"
action = "allow"
rule_name = "allow-egress"
disabled = false
description = "Allow egress"
enable_logging = false
match = {
dest_ip_ranges = ["0.0.0.0/0"]
layer4_configs = [
{
ip_protocol = "tcp"
ports = ["0-65535"]
},
{
ip_protocol = "udp"
ports = ["0-65535"]
},
]
}
},
{
priority = 510
direction = "EGRESS"
action = "goto_next"
rule_name = "rfc1918-egress"
disabled = false
description = "RFC1918 egress"
enable_logging = false
match = {
dest_ip_ranges = [
"192.168.0.0/16",
"10.0.0.0/8",
"172.16.0.0/12",
]
layer4_configs = [
{
ip_protocol = "all"
ports = []
}
]
}
},
{
priority = 4000
direction = "INGRESS"
action = "allow"
rule_name = "allow-bgp"
disabled = false
description = "Always allow bgp"
enable_logging = false
match = {
src_ip_ranges = ["10.0.0.0/8", ]
layer4_configs = [
{
ip_protocol = "tcp"
ports = ["179"]
},
]
}
},
{
priority = 5000
direction = "INGRESS"
action = "allow"
rule_name = "allow-ssh"
disabled = false
description = "Always allow SSH and RDP from IAP"
enable_logging = false
match = {
src_ip_ranges = ["35.235.240.0/20"]
layer4_configs = [
{
ip_protocol = "tcp"
ports = ["22", "3389"]
},
]
}
},
]
ingress_rules = var.enable_firewall_plus ? [
{
priority = 500
direction = "INGRESS"
action = "apply_security_profile_group"
security_profile_group = module.firewall_endpoints.0.security_profile_group_id
rule_name = "rfc1918-ingress"
disabled = false
description = "RFC1918 ingress"
enable_logging = true
match = {
src_ip_ranges = [
"192.168.0.0/16",
"10.0.0.0/8",
"172.16.0.0/12",
]
layer4_configs = [
{
ip_protocol = "all"
ports = []
}
]
}
},
] : [
{
priority = 500
direction = "INGRESS"
action = "allow"
security_profile_group = null
rule_name = "rfc1918-ingress"
disabled = false
description = "RFC1918 ingress"
enable_logging = true
match = {
src_ip_ranges = [
"192.168.0.0/16",
"10.0.0.0/8",
"172.16.0.0/12",
]
layer4_configs = [
{
ip_protocol = "all"
ports = []
}
]
}
},
]
firewall_rules = concat(local.default_rules, local.ingress_rules)
}
module "network_firewall_policy" {
source = "./modules/network-firewall-policy"
# source = "terraform-google-modules/network/google//modules/network-firewall-policy"
# version = "~> 9.1"
project_id = var.project_id
policy_name = "fp-${var.environment_code}-common-policies"
description = "Firewall policies to test firewall endpoints"
target_vpcs = []
rules = local.firewall_rules
}
resource "google_compute_network_firewall_policy_association" "default" {
for_each = { for vpc in module.vpc : vpc.network_name => vpc.network_id }
project = var.project_id
name = "${module.network_firewall_policy.fw_policy[0].name}-${element(split("/", each.value), length(split("/", each.value)) - 1)}"
attachment_target = each.value
firewall_policy = module.network_firewall_policy.fw_policy[0].name
}