-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.tf
398 lines (358 loc) · 12 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
##############################################################################
# Account Variables
# Copyright 2020 IBM
##############################################################################
# Comment this variable if running in schematics
variable ibmcloud_api_key {
description = "The IBM Cloud platform API key needed to deploy IAM enabled resources"
type = string
sensitive = true
}
# Comment out if not running in schematics
variable TF_VERSION {
default = "1.0"
type = string
description = "The version of the Terraform engine that's used in the Schematics workspace."
}
variable prefix {
description = "A unique identifier need to provision resources. Must begin with a letter"
type = string
default = "gcat-multizone"
validation {
error_message = "Unique ID must begin and end with a letter and contain only letters, numbers, and - characters."
condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix))
}
}
variable region {
description = "Region where resources will be created"
type = string
default = "us-south"
}
##############################################################################
##############################################################################
# Secrets Manager Variables
##############################################################################
variable secrets_manager_resource_group {
description = "Name of the resource group where the secrets mananger instance is provisione"
type = string
}
variable secrets_manager_name {
description = "Name of the secrets manager ID where the child API key is stored"
type = string
}
variable secret_guid {
description = "GUID of the secret to get the data from"
type = string
}
##############################################################################
##############################################################################
# Access Group Rules
##############################################################################
variable access_groups {
description = "A list of access groups to create"
type = list(
object({
name = string # Name of the group
description = string # Description of group
policies = list(
object({
name = string # Name of the policy
roles = list(string) # list of roles for the policy
resources = object({
resource_group = optional(string) # Name of the resource group the policy will apply to
resource_type = optional(string) # Name of the resource type for the policy ex. "resource-group"
service = optional(string) # Name of the service type for the policy ex. "cloud-object-storage"
resource = optional(string) # The resource of the policy definition
resource_instance_id = optional(string) # ID of a service instance to give permissions
})
})
)
dynamic_policies = optional(
list(
object({
name = string # Dynamic group name
identity_provider = string # URI for identity provider
expiration = number # How many hours authenticated users can work before refresh
conditions = object({
claim = string # key value to evaluate the condition against.
operator = string # The operation to perform on the claim. Supported values are EQUALS, EQUALS_IGNORE_CASE, IN, NOT_EQUALS_IGNORE_CASE, NOT_EQUALS, and CONTAINS.
value = string # Value to be compared agains
})
})
)
)
account_management_policies = optional(list(string))
invite_users = optional(list(string)) # Users to invite to the access group
})
)
default = []
}
##############################################################################
##############################################################################
# VPC Variables
##############################################################################
variable resource_group {
description = "Name of resource group where all infrastructure will be provisioned"
type = string
default = "gcat-landing-zone-dev"
validation {
error_message = "Unique ID must begin and end with a letter and contain only letters, numbers, and - characters."
condition = can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.resource_group))
}
}
variable classic_access {
description = "Enable VPC Classic Access. Note: only one VPC per region can have classic access"
type = bool
default = false
}
variable subnets {
description = "List of subnets for the vpc. For each item in each array, a subnet will be created."
type = object({
zone-1 = list(object({
name = string
cidr = string
public_gateway = optional(bool)
}))
zone-2 = list(object({
name = string
cidr = string
public_gateway = optional(bool)
}))
zone-3 = list(object({
name = string
cidr = string
public_gateway = optional(bool)
}))
})
default = {
zone-1 = [
{
name = "subnet-a"
cidr = "10.10.10.0/24"
public_gateway = true
}
],
zone-2 = [
{
name = "subnet-b"
cidr = "10.20.10.0/24"
public_gateway = true
}
],
zone-3 = [
{
name = "subnet-c"
cidr = "10.30.10.0/24"
public_gateway = true
}
]
}
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"
}
}
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 = true
zone-3 = true
}
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"
}
}
variable acl_rules {
description = "Access control list rule set"
type = 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 = "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 var.acl_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 var.acl_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 var.acl_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 var.acl_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
}
}
variable security_group_rules {
description = "A list of security group rules to be added to the default vpc security group"
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)
})
)
})
)
default = [
{
name = "allow-inbound-ping"
direction = "inbound"
remote = "0.0.0.0/0"
icmp = {
type = 8
}
},
{
name = "allow-inbound-ssh"
direction = "inbound"
remote = "0.0.0.0/0"
tcp = {
port_min = 22
port_max = 22
}
},
]
validation {
error_message = "Security group 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 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 = 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 = 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
}
}
##############################################################################