-
Notifications
You must be signed in to change notification settings - Fork 0
/
f5_security_group_config.tf
232 lines (213 loc) · 6.91 KB
/
f5_security_group_config.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
##############################################################################
# F5 Security Group Config
##############################################################################
locals {
##############################################################################
# Security group rules for each security group
##############################################################################
default_security_group_rules = [
{
name = "allow-ibm-inbound"
remote = "161.26.0.0/16"
direction = "inbound"
tcp = {
port_min = null
port_max = null
}
},
{
name = "allow-vpc-inbound"
remote = "10.0.0.0/8"
direction = "inbound"
tcp = {
port_min = null
port_max = null
}
},
{
name = "allow-vpc-outbound"
remote = "10.0.0.0/8"
direction = "outbound"
tcp = {
port_min = null
port_max = null
}
}
]
ibm_service_port_rules = [
for port in [53, 80, 443] :
{
name = "allow-ibm-tcp-${port}-outbound"
remote = "161.26.0.0/16"
direction = "outbound"
tcp = {
port_min = port
port_max = port
}
}
]
all_default_security_group_rules = concat(
local.default_security_group_rules,
local.ibm_service_port_rules
)
all_bastion_cidr_blocks = concat(
[
for zone in [1, 2, 3] :
"10.${4 + zone}.60.0/24" if zone <= var.bastion_subnet_zones
],
var.bastion_cidr_blocks
)
##############################################################################
##############################################################################
# Security Groups
##############################################################################
security_groups = {
##############################################################################
# F5 Bastion Security Group
##############################################################################
f5-bastion = {
name = "f5-bastion-sg"
rules = flatten([
# For each bastion CIDR create a rule allowing inbound traffic to 3023-3025 and 3080
for cidr in local.all_bastion_cidr_blocks :
[
{
name = "allow-bastion-cidr-${index(local.all_bastion_cidr_blocks, cidr) + 1}-inbound-3023-3025"
direction = "inbound"
remote = cidr
tcp = {
port_min = null
port_max = null
source_port_min = 3023
source_port_max = 3025
}
},
{
name = "allow-bastion-cidr-${index(local.all_bastion_cidr_blocks, cidr) + 1}-inbound-3080"
direction = "inbound"
remote = cidr
tcp = {
port_min = null
port_max = null
source_port_max = 3080
source_port_min = 3080
}
},
{
name = "allow-bastion-cidr-${index(local.all_bastion_cidr_blocks, cidr) + 1}-outbound-3023-3025"
direction = "outbound"
remote = cidr
tcp = {
port_min = 3023
port_max = 3025
source_port_max = null
source_port_min = null
}
},
{
name = "allow-bastion-cidr-${index(local.all_bastion_cidr_blocks, cidr) + 1}-outbound-3080"
direction = "outbound"
remote = cidr
tcp = {
port_max = 3080
port_min = 3080
source_port_max = null
source_port_min = null
}
}
]
])
}
##############################################################################
##############################################################################
# F5 External Security Group
##############################################################################
f5-external = {
name = "f5-external-sg"
rules = [
{
name = "allow-inbound-443"
direction = "inbound"
remote = "0.0.0.0/0"
tcp = {
port_max = 443
port_min = 443
source_port_max = null
source_port_min = null
}
},
{
name = "allow-outbound-443"
direction = "inbound"
remote = "0.0.0.0/0"
tcp = {
port_min = null
port_max = null
source_port_max = 443
source_port_min = 443
}
}
]
}
##############################################################################
##############################################################################
# F5 Management Security Group
##############################################################################
f5-management = {
name = "f5-management-sg"
rules = flatten([
[
# For each bastion CIDR create a rule allowing inbound traffic to 443 and 22
for cidr in var.bastion_cidr_blocks :
[
{
name = "allow-bastion-cidr-${index(var.bastion_cidr_blocks, cidr) + 1}-inbound-443"
direction = "inbound"
remote = cidr
tcp = {
port_max = 443
port_min = 443
}
},
{
name = "allow-bastion-cidr-${index(var.bastion_cidr_blocks, cidr) + 1}-inbound-22"
direction = "inbound"
remote = cidr
tcp = {
port_max = 22
port_min = 22
}
}
]
],
local.all_default_security_group_rules
])
}
##############################################################################
##############################################################################
# F5 Workload Security Group
##############################################################################
f5-workload = {
name = "f5-workload-sg"
rules = concat(
[
# for each workload cidr add a rule to allow 443 inbound traffic
for subnet in var.workload_cidr_blocks :
{
name = "allow-workload-subnet-${index(var.workload_cidr_blocks, subnet) + 1}"
remote = subnet
direction = "inbound"
tcp = {
port_max = 443
port_min = 443
}
}
],
local.all_default_security_group_rules
)
}
##############################################################################
}
##############################################################################
}
##############################################################################