-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.tf
411 lines (363 loc) · 12.4 KB
/
variables.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
##############################################################################
# Module Level Variables
##############################################################################
variable "name" {
description = "Name for VPC"
type = string
}
variable "resource_group_id" {
description = "The resource group ID where the VPC to be created"
type = string
}
variable "region" {
description = "The region to which to deploy the VPC"
type = string
}
variable "prefix" {
description = "The prefix that you would like to append to your resources"
type = string
}
variable "tags" {
description = "List of Tags for the resource created"
type = list(string)
default = null
}
##############################################################################
##############################################################################
# Optional VPC Variables
##############################################################################
variable "network_cidr" {
description = "Network CIDR for the VPC. This is used to manage network ACL rules for cluster provisioning."
type = string
default = "10.0.0.0/8"
}
variable "classic_access" {
description = "OPTIONAL - Classic Access to the VPC"
type = bool
default = false
}
variable "use_manual_address_prefixes" {
description = "OPTIONAL - Use manual address prefixes for VPC"
type = bool
default = false
}
variable "default_network_acl_name" {
description = "OPTIONAL - Name of the Default ACL. If null, a name will be automatically generated"
type = string
default = null
}
variable "default_security_group_name" {
description = "OPTIONAL - Name of the Default Security Group. If null, a name will be automatically generated"
type = string
default = null
}
variable "default_routing_table_name" {
description = "OPTIONAL - Name of the Default Routing Table. If null, a name will be automatically generated"
type = string
default = null
}
variable "address_prefixes" {
description = "OPTIONAL - IP range that will be defined for the VPC for a certain location. Use only with manual address prefixes"
type = object({
zone-1 = optional(list(string))
zone-2 = optional(list(string))
zone-3 = optional(list(string))
})
default = {
zone-1 = null
zone-2 = null
zone-3 = null
}
validation {
error_message = "Keys for `use_public_gateways` must be in the order `zone-1`, `zone-2`, `zone-3`."
condition = var.address_prefixes == null ? true : (keys(var.address_prefixes)[0] == "zone-1" && keys(var.address_prefixes)[1] == "zone-2" && keys(var.address_prefixes)[2] == "zone-3")
}
}
##############################################################################
##############################################################################
# Network ACLs
##############################################################################
variable "network_acls" {
description = "List of ACLs to create. Rules can be automatically created to allow inbound and outbound traffic from a VPC tier by adding the name of that tier to the `network_connections` list. Rules automatically generated by these network connections will be added at the beginning of a list, and will be web-tierlied to traffic first. At least one rule must be provided for each ACL."
type = list(
object({
name = string
network_connections = optional(list(string))
add_cluster_rules = optional(bool)
rules = list(
object({
name = string
action = string
destination = string
direction = string
source = string
tcp = optional(
object({
port_max = optional(number)
port_min = optional(number)
source_port_max = optional(number)
source_port_min = optional(number)
})
)
udp = optional(
object({
port_max = optional(number)
port_min = optional(number)
source_port_max = optional(number)
source_port_min = optional(number)
})
)
icmp = optional(
object({
type = optional(number)
code = optional(number)
})
)
})
)
})
)
default = [
{
name = "vpc-acl"
add_cluster_rules = true
rules = [
{
name = "allow-all-inbound"
action = "allow"
direction = "inbound"
destination = "0.0.0.0/0"
source = "0.0.0.0/0"
},
{
name = "allow-all-outbound"
action = "allow"
direction = "outbound"
destination = "0.0.0.0/0"
source = "0.0.0.0/0"
}
]
}
]
validation {
error_message = "ACL rules can only have one of `icmp`, `udp`, or `tcp`."
condition = length(distinct(
# Get flat list of results
flatten([
# Check through rules
for rule in flatten([var.network_acls.*.rules]) :
# Return true if there is more than one of `icmp`, `udp`, or `tcp`
true if length(
[
for type in ["tcp", "udp", "icmp"] :
true if rule[type] != null
]
) > 1
])
)) == 0 # Checks for length. If all fields all correct, array will be empty
}
validation {
error_message = "ACL rule actions can only be `allow` or `deny`."
condition = length(distinct(
flatten([
# Check through rules
for rule in flatten([var.network_acls.*.rules]) :
# Return false action is not valid
false if !contains(["allow", "deny"], rule.action)
])
)) == 0
}
validation {
error_message = "ACL rule direction can only be `inbound` or `outbound`."
condition = length(distinct(
flatten([
# Check through rules
for rule in flatten([var.network_acls.*.rules]) :
# Return false if direction is not valid
false if !contains(["inbound", "outbound"], rule.direction)
])
)) == 0
}
validation {
error_message = "ACL rule names must match the regex pattern ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$."
condition = length(distinct(
flatten([
# Check through rules
for rule in flatten([var.network_acls.*.rules]) :
# Return false if direction is not valid
false if !can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", rule.name))
])
)) == 0
}
}
##############################################################################
##############################################################################
# Public Gateways
##############################################################################
variable "use_public_gateways" {
description = "Create a public gateway in any of the three zones with `true`."
type = object({
zone-1 = optional(bool)
zone-2 = optional(bool)
zone-3 = optional(bool)
})
default = {
zone-1 = true
zone-2 = false
zone-3 = false
}
validation {
error_message = "Keys for `use_public_gateways` must be in the order `zone-1`, `zone-2`, `zone-3`."
condition = keys(var.use_public_gateways)[0] == "zone-1" && keys(var.use_public_gateways)[1] == "zone-2" && keys(var.use_public_gateways)[2] == "zone-3"
}
}
##############################################################################
##############################################################################
# Subnets
##############################################################################
variable "subnets" {
description = "List of subnets for the vpc. For each item in each array, a subnet will be created. Items can be either CIDR blocks or total ipv4 addressess. Public gateways will be enabled only in zones where a gateway has been created"
type = object({
zone-1 = list(object({
name = string
cidr = string
public_gateway = optional(bool)
acl_name = string
}))
zone-2 = list(object({
name = string
cidr = string
public_gateway = optional(bool)
acl_name = string
}))
zone-3 = list(object({
name = string
cidr = string
public_gateway = optional(bool)
acl_name = string
}))
})
default = {
zone-1 = [
{
name = "subnet-a"
cidr = "10.10.10.0/24"
public_gateway = true
acl_name = "vpc-acl"
}
],
zone-2 = [
{
name = "subnet-b"
cidr = "10.20.10.0/24"
public_gateway = true
acl_name = "vpc-acl"
}
],
zone-3 = [
{
name = "subnet-c"
cidr = "10.30.10.0/24"
public_gateway = false
acl_name = "vpc-acl"
}
]
}
validation {
error_message = "Keys for `subnets` must be in the order `zone-1`, `zone-2`, `zone-3`."
condition = keys(var.subnets)[0] == "zone-1" && keys(var.subnets)[1] == "zone-2" && keys(var.subnets)[2] == "zone-3"
}
}
##############################################################################
##############################################################################
# Default Security Group Rules
##############################################################################
variable "security_group_rules" {
description = "A list of security group rules to be added to the default vpc security group"
default = [{
name = "default-sgr"
direction = "inbound"
remote = "10.0.0.0/8"
}]
type = list(
object({
name = string
direction = string
remote = string
tcp = optional(
object({
port_max = optional(number)
port_min = optional(number)
})
)
udp = optional(
object({
port_max = optional(number)
port_min = optional(number)
})
)
icmp = optional(
object({
type = optional(number)
code = optional(number)
})
)
})
)
validation {
error_message = "Security group rules can only have one of `icmp`, `udp`, or `tcp`."
condition = (var.security_group_rules == null || length(var.security_group_rules) == 0) ? true : length(distinct(
# Get flat list of results
flatten([
# Check through rules
for rule in var.security_group_rules :
# Return true if there is more than one of `icmp`, `udp`, or `tcp`
true if length(
[
for type in ["tcp", "udp", "icmp"] :
true if rule[type] != null
]
) > 1
])
)) == 0 # Checks for length. If all fields all correct, array will be empty
}
validation {
error_message = "Security group rule direction can only be `inbound` or `outbound`."
condition = (var.security_group_rules == null || length(var.security_group_rules) == 0) ? true : length(distinct(
flatten([
# Check through rules
for rule in var.security_group_rules :
# Return false if direction is not valid
false if !contains(["inbound", "outbound"], rule.direction)
])
)) == 0
}
validation {
error_message = "Security group rule names must match the regex pattern ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$."
condition = (var.security_group_rules == null || length(var.security_group_rules) == 0) ? true : length(distinct(
flatten([
# Check through rules
for rule in var.security_group_rules :
# Return false if direction is not valid
false if !can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", rule.name))
])
)) == 0
}
}
##############################################################################
##############################################################################
# Add routes to VPC
##############################################################################
variable "routes" {
description = "OPTIONAL - Allows you to specify the next hop for packets based on their destination address"
type = list(
object({
name = string
zone = number
destination = string
next_hop = string
})
)
default = []
}
##############################################################################