generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.tf
499 lines (443 loc) · 15.6 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
##############################################################################
variable "resource_group_id" {
description = "ID of resource group to create VSI and block storage volumes. If you wish to create the block storage volumes in a different resource group, you can optionally set that directly in the 'block_storage_volumes' variable."
type = string
}
variable "prefix" {
description = "The value that you would like to prefix to the name of the resources provisioned by this module. Explicitly set to null if you do not wish to use a prefix. This value is ignored if using one of the optional variables for explicit control over naming."
type = string
default = null
}
variable "zone" {
description = "The zone to create the resource in"
type = string
}
variable "tags" {
description = "List of tags to apply to resources created by this module."
type = list(string)
default = []
}
variable "access_tags" {
type = list(string)
description = "A list of access tags to apply to the VSI resources created by the module. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial."
default = []
validation {
condition = alltrue([
for tag in var.access_tags : can(regex("[\\w\\-_\\.]+:[\\w\\-_\\.]+", tag)) && length(tag) <= 128
])
error_message = "Tags must match the regular expression \"[\\w\\-_\\.]+:[\\w\\-_\\.]+\". For more information, see https://cloud.ibm.com/docs/account?topic=account-tag&interface=ui#limits."
}
}
##############################################################################
##############################################################################
# VPC Variables
##############################################################################
variable "vpc_id" {
description = "ID of VPC"
type = string
}
variable "subnets" {
description = "A list of subnet IDs where VSI will be deployed"
type = list(
object({
name = string
id = string
zone = string
cidr = optional(string)
crn = optional(string)
})
)
}
##############################################################################
##############################################################################
# Autoscale (Instance template) Variables
##############################################################################
variable "instance_tmplt_name" {
description = "The name to assign the instance template. If no name is provided then the default will be `{prefix}-ins-tmplt`."
type = string
default = null
}
variable "availability_policy_host_failure" {
description = "The availability policy to use for this virtual server instance. The action to perform if the compute host experiences a failure"
type = string
default = "restart"
}
variable "dedicated_host" {
description = "The placement restrictions to use for the virtual server instance. Unique Identifier of the dedicated host where the instance is placed."
type = string
default = null
}
variable "dedicated_host_group" {
description = "The placement restrictions to use for the virtual server instance. Unique Identifier of the dedicated host group where the instance is placed."
type = string
default = null
}
variable "image_id" {
description = "Image ID used for VSI. Run 'ibmcloud is images' to find available images in a region"
type = string
}
variable "ssh_key_ids" {
description = "ssh key ids to use in creating vsi"
type = list(string)
}
variable "machine_type" {
description = "VSI machine type. Run 'ibmcloud is instance-profiles' to get a list of regional profiles"
type = string
}
variable "user_data" {
description = "User data to initialize VSI deployment"
type = string
default = null
}
variable "boot_volume_encryption_key" {
description = "CRN of boot volume encryption key"
default = null
type = string
}
variable "auto_delete_volumes" {
type = bool
description = "Auto delete volumes when the instance is deleted"
default = true
}
variable "existing_kms_instance_guid" {
description = "The GUID of the Hyper Protect Crypto Services instance in which the key specified in var.boot_volume_encryption_key is coming from."
type = string
default = null
}
variable "allow_ip_spoofing" {
description = "Allow IP spoofing on the primary network interface"
type = bool
default = false
}
variable "create_security_group" {
description = "Create security group for VSI. If this is passed as false, the default will be used"
type = bool
}
variable "placement_group_id" {
description = "Unique Identifier of the Placement Group for restricting the placement of the instance, default behaviour is placement on any host"
type = string
default = null
}
variable "security_group" {
description = "Security group created for VSI"
type = object({
name = string
add_ibm_cloud_internal_rules = optional(bool, false)
rules = list(
object({
name = string
direction = string
source = string
tcp = optional(
object({
port_max = number
port_min = number
})
)
udp = optional(
object({
port_max = number
port_min = number
})
)
icmp = optional(
object({
type = number
code = number
})
)
})
)
})
validation {
error_message = "Each security group rule must have a unique name."
condition = (
var.security_group == null
? true
: length(distinct(var.security_group.rules[*].name)) == length(var.security_group.rules[*].name)
)
}
validation {
error_message = "Security group rule direction can only be `inbound` or `outbound`."
condition = var.security_group == null ? true : length(
distinct(
flatten([
for rule in var.security_group.rules :
false if !contains(["inbound", "outbound"], rule.direction)
])
)
) == 0
}
default = null
}
variable "security_group_ids" {
description = "IDs of additional security groups to be added to VSI deployment primary interface. A VSI interface can have a maximum of 5 security groups."
type = list(string)
default = []
validation {
error_message = "Security group IDs must be unique."
condition = length(var.security_group_ids) == length(distinct(var.security_group_ids))
}
validation {
error_message = "No more than 5 security groups can be added to a VSI deployment."
condition = length(var.security_group_ids) <= 5
}
}
variable "kms_encryption_enabled" {
type = bool
description = "Set this to true to control the encryption keys used to encrypt the data that for the block storage volumes for VPC. If set to false, the data is encrypted by using randomly generated keys. For more info on encrypting block storage volumes, see https://cloud.ibm.com/docs/vpc?topic=vpc-creating-instances-byok"
default = false
}
variable "skip_iam_authorization_policy" {
type = bool
description = "Set to true to skip the creation of an IAM authorization policy that permits all Storage Blocks to read the encryption key from the KMS instance. If set to false, pass in a value for the KMS instance in the existing_kms_instance_guid variable. In addition, no policy is created if var.kms_encryption_enabled is set to false."
default = false
}
variable "block_storage_volumes" {
description = "List describing the block storage volumes that will be attached to each vsi"
type = list(
object({
name = string
profile = string
capacity = optional(number)
iops = optional(number)
encryption_key = optional(string)
resource_group_id = optional(string)
})
)
default = []
validation {
error_message = "Each block storage volume must have a unique name."
condition = length(distinct(var.block_storage_volumes[*].name)) == length(var.block_storage_volumes)
}
}
variable "load_balancers" {
description = "Load balancers to add to VSI"
type = list(
object({
name = string
type = string
logging = optional(bool)
listener_port = number
listener_protocol = string
connection_limit = number
idle_connection_timeout = optional(number)
algorithm = string
certificate_instance = optional(string)
protocol = string
health_delay = number
health_retries = number
health_timeout = number
health_type = string
pool_member_port = string
profile = optional(string)
dns = optional(
object({
instance_crn = string
zone_id = string
})
)
security_group = optional(
object({
name = string
add_ibm_cloud_internal_rules = optional(bool, false)
rules = list(
object({
name = string
direction = string
source = string
tcp = optional(
object({
port_max = number
port_min = number
})
)
udp = optional(
object({
port_max = number
port_min = number
})
)
icmp = optional(
object({
type = number
code = number
})
)
})
)
})
)
policies = optional(
list(object({
name = string
action = string
priority = number
rules = optional(list(
object({
condition = string
type = string
value = string
field = string
})
))
target = optional(list(
object({
url = optional(string)
http_status_code = optional(string)
pool_id = optional(string)
listener_id = optional(string)
})
))
})
))
})
)
default = []
validation {
error_message = "Only one load balancer can be defined for autoscaling."
condition = length(var.load_balancers) < 2
}
validation {
error_message = "Load balancer names must match the regex pattern ^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$."
condition = length(distinct(
flatten([
# Check through rules
for load_balancer in var.load_balancers :
# Return false if direction is not valid
false if !can(regex("^([a-z]|[a-z][-a-z0-9]*[a-z0-9])$", load_balancer.name))
])
)) == 0
}
validation {
error_message = "Load balancer idle_connection_timeout must be between 50 and 7200."
condition = length(
flatten([
for load_balancer in var.load_balancers :
load_balancer.idle_connection_timeout != null ?
(load_balancer.idle_connection_timeout < 50 || load_balancer.idle_connection_timeout > 7200) ? [true] : []
: []
])
) == 0
}
validation {
error_message = "Load Balancer Pool algorithm can only be `round_robin`, `weighted_round_robin`, or `least_connections`."
condition = length(
flatten([
for load_balancer in var.load_balancers :
true if !contains(["round_robin", "weighted_round_robin", "least_connections"], load_balancer.algorithm)
])
) == 0
}
validation {
error_message = "Load Balancer Pool Protocol can only be `http`, `https`, or `tcp`."
condition = length(
flatten([
for load_balancer in var.load_balancers :
true if !contains(["http", "https", "tcp"], load_balancer.protocol)
])
) == 0
}
validation {
error_message = "If Load Balancer listener protocol is `https`, certificate_instance variable must be defined"
condition = length(
flatten([
for load_balancer in var.load_balancers :
true if("https" == load_balancer.listener_protocol && load_balancer.certificate_instance == null)
])
) == 0
}
validation {
error_message = "Pool health delay must be greater than the timeout."
condition = length(
flatten([
for load_balancer in var.load_balancers :
true if load_balancer.health_delay < load_balancer.health_timeout
])
) == 0
}
validation {
error_message = "Load Balancer Pool Health Check Type can only be `http`, `https`, or `tcp`."
condition = length(
flatten([
for load_balancer in var.load_balancers :
true if !contains(["http", "https", "tcp"], load_balancer.health_type)
])
) == 0
}
validation {
error_message = "Each load balancer must have a unique name."
condition = length(distinct(var.load_balancers[*].name)) == length(var.load_balancers[*].name)
}
}
##############################################################################
##############################################################################
# Autoscale (Instance Group) Variables
##############################################################################
variable "instance_group_name" {
description = "The name to assign the instance group. If no name is provided then the default will be `{prefix}-ins-group`."
type = string
default = null
}
variable "instance_count" {
type = number
description = "The number of instances to create in the instance group."
default = null
}
variable "application_port" {
type = number
description = "The instance group uses when scaling up instances to supply the port for the Load Balancer pool member."
default = null
}
variable "group_managers" {
description = "Instance group manager to add to the instance group"
type = list(
object({
name = string
aggregation_window = optional(number)
cooldown = optional(number)
enable_manager = optional(bool)
manager_type = string
max_membership_count = optional(number)
min_membership_count = optional(number)
actions = optional(
list(
object({
name = string
cron_spec = optional(string)
membership_count = optional(number)
max_membership_count = optional(number)
min_membership_count = optional(number)
run_at = optional(string)
})
)
)
policies = optional(
list(
object({
name = string
metric_type = string
metric_value = number
policy_type = string
})
)
)
})
)
default = []
validation {
error_message = "Each Instance group manager must have a unique name."
condition = length(distinct(var.group_managers[*].name)) == length(var.group_managers[*].name)
}
validation {
error_message = "Manager type can only be `autoscale`, or `scheduled`."
condition = length(
flatten([
for group_manager in var.group_managers :
true if !contains(["autoscale", "scheduled"], group_manager.manager_type)
])
) == 0
}
}