-
Notifications
You must be signed in to change notification settings - Fork 7
/
variables.tf
499 lines (446 loc) · 15.9 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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
##############################################################################
# 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 = "jv-eu-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.prefix))
}
}
variable region {
description = "Region where VPC will be created"
type = string
default = "us-south"
}
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))
}
}
##############################################################################
##############################################################################
# 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_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 = list(string) # Users to invite to the access group
})
)
default = [
{
name = "admin"
description = "An example admin group"
policies = [
{
name = "admin_all"
resources = {
resource_group = "gcat-landing-zone-dev"
}
roles = ["Administrator","Manager"]
}
]
dynamic_policies = []
invite_users = [ "[email protected]" ]
},
{
name = "dev"
description = "A developer access group"
policies = [
{
name = "dev_view_vpc"
resources = {
resource_group = "gcat-landing-zone-dev"
service = "id"
}
roles = ["Viewer"]
}
]
invite_users = ["[email protected]"]
}
]
}
##############################################################################
##############################################################################
# VPC Variables
##############################################################################
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-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-all-inbound"
direction = "inbound"
remote = "0.0.0.0/0"
},
{
name = "allow-all-outbound"
direction = "outbound"
remote = "0.0.0.0/0"
},
]
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
}
}
##############################################################################
##############################################################################
# Cluster Variables
##############################################################################
variable machine_type {
description = "The flavor of VPC worker node to use for your cluster. Use `ibmcloud ks flavors` to find flavors for a region."
type = string
default = "bx2.4x16"
}
variable workers_per_zone {
description = "Number of workers to provision in each subnet"
type = number
default = 2
validation {
error_message = "Each zone must contain at least 2 workers."
condition = var.workers_per_zone >= 2
}
}
variable entitlement {
description = "If you purchased an IBM Cloud Cloud Pak that includes an entitlement to run worker nodes that are installed with OpenShift Container Platform, enter entitlement to create your cluster with that entitlement so that you are not charged twice for the OpenShift license. Note that this option can be set only when you create the cluster. After the cluster is created, the cost for the OpenShift license occurred and you cannot disable this charge."
type = string
default = "cloud_pak"
}
variable kube_version {
description = "Specify the Kubernetes version, including the major.minor version. To see available versions, run `ibmcloud ks versions`. To get the default version, leave as `default`."
type = string
default = "default"
validation {
error_message = "To create a ROKS cluster, the kube version must include `openshift`."
condition = can(regex(".*openshift", var.kube_version)) || var.kube_version == "default"
}
}
variable wait_till {
description = "To avoid long wait times when you run your Terraform code, you can specify the stage when you want Terraform to mark the cluster resource creation as completed. Depending on what stage you choose, the cluster creation might not be fully completed and continues to run in the background. However, your Terraform code can continue to run without waiting for the cluster to be fully created. Supported args are `MasterNodeReady`, `OneWorkerNodeReady`, and `IngressReady`"
type = string
default = "IngressReady"
validation {
error_message = "`wait_till` value must be one of `MasterNodeReady`, `OneWorkerNodeReady`, or `IngressReady`."
condition = contains([
"MasterNodeReady",
"OneWorkerNodeReady",
"IngressReady"
], var.wait_till)
}
}
variable tags {
description = "A list of tags to add to the cluster"
type = list(string)
default = []
validation {
error_message = "Tags must match the regex `^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`."
condition = length([
for name in var.tags:
false if !can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", name))
]) == 0
}
}
variable worker_pools {
description = "List of maps describing worker pools"
type = list(object({
name = string
machine_type = string
workers_per_zone = number
}))
default = [
]
validation {
error_message = "Worker pool names must match the regex `^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$`."
condition = length([
for pool in var.worker_pools:
false if !can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", pool.name))
]) == 0
}
validation {
error_message = "Worker pools cannot have duplicate names."
condition = length(distinct([
for pool in var.worker_pools:
pool.name
])) == length(var.worker_pools)
}
validation {
error_message = "Worker pools must have at least two workers per zone."
condition = length([
for pool in var.worker_pools:
false if pool.workers_per_zone < 2
]) == 0
}
}
##############################################################################