-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.tf
More file actions
466 lines (408 loc) · 18.1 KB
/
variables.tf
File metadata and controls
466 lines (408 loc) · 18.1 KB
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
variable "name_prefix" {
description = "A unique name prefix used to name resources."
type = string
}
variable "tags" {
description = "A map of tags to assign to all resources."
type = map(string)
default = {}
}
# Launch Template Configuration
variable "use_launch_template" {
description = "Set to true to use a Launch Template, false to use Launch Configuration (Launch Templates are recommended)."
type = bool
default = true
}
variable "create_launch_template" {
description = "Set to true to create a new Launch Template. If false, specify `launch_template_id` or `launch_template_name`."
type = bool
default = true
}
variable "launch_template_id" {
description = "The ID of an existing Launch Template to use. Required if `create_launch_template` is false and `use_launch_template` is true."
type = string
default = null
}
variable "launch_template_name" {
description = "The Name of an existing Launch Template to use. Can be used instead of `launch_template_id` if `create_launch_template` is false and `use_launch_template` is true."
type = string
default = null
}
variable "launch_template_version" {
description = "The version of the launch template to use ($Latest, $Default, or version number). Defaults to $Default."
type = string
default = "$Default"
}
variable "launch_template_description" {
description = "Description for the created Launch Template."
type = string
default = null
}
variable "launch_template_update_default_version" {
description = "Whether to update the default version of the Launch Template when changes are made."
type = bool
default = true
}
variable "launch_template_tags" {
description = "Additional tags to apply specifically to the Launch Template."
type = map(string)
default = {}
}
# Launch Template Data (Only used if create_launch_template = true)
variable "lt_image_id" {
description = "The AMI ID to use for the instances."
type = string
default = null # Required if creating a new LT/LC
}
variable "lt_instance_type" {
description = "The instance type to use for the instances."
type = string
default = null # Required if creating a new LT/LC
}
variable "lt_key_name" {
description = "The key name to use for the instances."
type = string
default = null
}
variable "lt_iam_instance_profile_arn" {
description = "The ARN of the IAM instance profile to associate with instances."
type = string
default = null
}
variable "lt_iam_instance_profile_name" {
description = "The name of the IAM instance profile to associate with instances (alternative to ARN)."
type = string
default = null
}
variable "lt_security_group_ids" {
description = "A list of security group IDs to associate with instances."
type = list(string)
default = null # Often required
}
variable "lt_user_data_base64" {
description = "The Base64-encoded user data to provide when launching the instance."
type = string
default = null
}
variable "lt_associate_public_ip_address" {
description = "Whether to associate a public IP address with instances in the network interface. Depends on subnet settings."
type = bool
default = null # Terraform default is false if not specified
}
variable "lt_monitoring_enabled" {
description = "Whether detailed monitoring is enabled for the instances (CloudWatch)."
type = bool
default = false
}
variable "lt_ebs_optimized" {
description = "If true, the instance is launched with EBS optimization enabled."
type = bool
default = null # Defaults based on instance type
}
variable "lt_metadata_options" {
description = "Instance Metadata Options (IMDS). Object with: http_endpoint (enabled/disabled), http_tokens (optional/required), http_put_response_hop_limit, instance_metadata_tags (enabled/disabled)."
type = object({
http_endpoint = optional(string)
http_tokens = optional(string)
http_put_response_hop_limit = optional(number)
instance_metadata_tags = optional(string)
})
default = {
http_tokens = "required" # Default to IMDSv2 required
http_endpoint = "enabled"
http_put_response_hop_limit = 1
instance_metadata_tags = "disabled"
}
}
variable "lt_block_device_mappings" {
description = "Specify volumes to attach to the instance besides the root volume. List of objects, see AWS provider docs for `aws_launch_template` `block_device_mappings` structure (each object needs at least device_name)."
type = list(object({
device_name = string
ebs = object({
volume_size = optional(number)
volume_type = optional(string)
iops = optional(number)
throughput = optional(number)
kms_key_id = optional(string)
encrypted = optional(bool)
delete_on_termination = optional(bool)
snapshot_id = optional(string)
})
no_device = optional(string)
}))
default = []
}
variable "lt_root_block_device" {
description = "Customize the root block device. Object with: volume_type, volume_size, iops, throughput, encrypted, kms_key_id, delete_on_termination. Applied via block_device_mappings if needed."
type = object({
volume_type = optional(string)
volume_size = optional(number)
iops = optional(number)
throughput = optional(number)
encrypted = optional(bool)
kms_key_id = optional(string)
delete_on_termination = optional(bool)
})
default = {} # Use defaults from the AMI unless specified
}
variable "lt_tag_specifications" {
description = "Tag specifications for resources created from the launch template (instance, volume, etc.). List of objects with `resource_type` and `tags`."
type = list(object({ resource_type = string, tags = map(string) }))
default = null # If null, default instance/volume tags may be applied based on ASG tags
}
variable "lt_network_interface_settings" {
description = "Network interface settings for the launch template. If null, only basic public IP association is configured."
type = object({
associate_public_ip_address = optional(bool)
delete_on_termination = optional(bool, true)
security_groups = optional(list(string))
subnet_id = optional(string)
ipv6_address_count = optional(number)
ipv6_addresses = optional(list(string))
network_interface_id = optional(string)
private_ip_address = optional(string)
ipv4_address_count = optional(number)
ipv4_addresses = optional(list(string))
interface_type = optional(string)
})
default = null
}
# Launch Configuration (Legacy - Only if use_launch_template = false)
variable "create_launch_configuration" {
description = "Set to true to create a new Launch Configuration. If false, specify `launch_configuration_name`."
type = bool
default = true
}
variable "launch_configuration_name" {
description = "The name of an existing Launch Configuration to use. Required if `create_launch_configuration` is false and `use_launch_template` is false."
type = string
default = null
}
# Note: Many `lt_*` variables map directly to launch configuration arguments.
# The module will use relevant `lt_*` variables if `use_launch_template` is false
# and `create_launch_configuration` is true.
# Explicit LC-only vars:
variable "lc_spot_price" {
description = "The maximum price to pay for Spot instances. Only used for Launch Configurations."
type = string
default = null
}
variable "lc_enable_monitoring" {
description = "Enables/disables detailed monitoring. Alias for `lt_monitoring_enabled` for LC."
type = bool
default = false
}
variable "lc_associate_public_ip_address" {
description = "Associate a public IP address with instances. Alias for `lt_associate_public_ip_address` for LC."
type = bool
default = null
}
# Auto Scaling Group Configuration
variable "vpc_zone_identifier" {
description = "A list of subnet IDs associated with the Auto Scaling group. Required."
type = list(string)
}
variable "min_size" {
description = "The minimum number of instances in the Auto Scaling group."
type = number
}
variable "max_size" {
description = "The maximum number of instances in the Auto Scaling group."
type = number
}
variable "desired_capacity" {
description = "The desired number of instances in the Auto Scaling group. If null, defaults to `min_size`."
type = number
default = null
}
variable "health_check_type" {
description = "Controls how health checking is done. Valid values are `EC2` or `ELB`. Default is `EC2`."
type = string
default = "EC2"
validation {
condition = contains(["EC2", "ELB"], var.health_check_type)
error_message = "Valid values for health_check_type are EC2 or ELB."
}
}
variable "health_check_grace_period" {
description = "Time (in seconds) after instance comes into service before checking health. Default is 300 seconds."
type = number
default = 300
}
variable "target_group_arns" {
description = "A list of ARNs of Application/Network Load Balancer Target Groups to associate with the ASG."
type = list(string)
default = []
}
variable "load_balancers" {
description = "A list of names of Classic Load Balancers to associate with the ASG. (Use `target_group_arns` for ALB/NLB)."
type = list(string)
default = []
}
variable "termination_policies" {
description = "A list of policies to decide which instances to terminate first during scale-in."
type = list(string)
default = [
"Default" # See AWS docs for other options like OldestInstance, NewestInstance, OldestLaunchTemplate, etc.
]
}
variable "suspended_processes" {
description = "A list of processes to suspend for the Auto Scaling group (e.g., Launch, Terminate, HealthCheck, ReplaceUnhealthy, AZRebalance, AlarmNotification, ScheduledActions, AddToLoadBalancer)."
type = list(string)
default = []
}
variable "protect_from_scale_in" {
description = "Allows setting instance protection. Instances launched will be protected from scale-in actions."
type = bool
default = false
}
variable "service_linked_role_arn" {
description = "The ARN of the service-linked role that Auto Scaling uses to call other AWS services on your behalf. By default, AWS creates this role."
type = string
default = null
}
variable "wait_for_capacity_timeout" {
description = "How long Terraform should wait for the ASG to possess the desired capacity (in minutes). Setting this overrides the default behavior of waiting for at least one instance to be healthy."
type = string
default = "10m" # Terraform default
}
variable "force_delete" {
description = "Allows deleting the Auto Scaling Group without waiting for instances to terminate. Use with caution."
type = bool
default = false
}
variable "force_delete_warm_pool" {
description = "Allows deleting the Auto Scaling Group without waiting for the warm pool to be deleted."
type = bool
default = false
}
variable "max_instance_lifetime" {
description = "The maximum amount of time, in seconds, that an instance can be in service (useful for patching/updates)."
type = number
default = null
}
variable "capacity_rebalance" {
description = "Indicates whether Capacity Rebalancing is enabled (attempts to replace Spot Instances before interruption). Only applies if using Spot Instances in the Launch Template/Configuration."
type = bool
default = false
}
variable "instance_refresh" {
description = "Configure instance refresh settings. Object with `strategy`, `preferences` (min_healthy_percentage, instance_warmup), and `triggers`."
type = object({
strategy = string # "Rolling" or "Replacing"
preferences = optional(object({
min_healthy_percentage = optional(number)
instance_warmup = optional(number)
checkpoint_delay = optional(number)
checkpoint_percentages = optional(list(number))
skip_matching = optional(bool)
auto_rollback = optional(bool)
}))
triggers = optional(list(string)) # e.g. ["launch_template", "tags"]
})
default = null
validation {
condition = var.instance_refresh == null || contains(["Rolling", "Replacing"], var.instance_refresh.strategy)
error_message = "The instance_refresh strategy must be one of: Rolling or Replacing."
}
}
variable "warm_pool" {
description = "Configure a warm pool for the ASG. Object with `pool_state`, `min_size`, `max_group_prepared_capacity`, `instance_reuse_policy` (object with `reuse_on_scale_in`)."
type = object({
pool_state = optional(string) # "Stopped", "Running", or "Hibernated"
min_size = optional(number)
max_group_prepared_capacity = optional(number)
instance_reuse_policy = optional(object({
reuse_on_scale_in = optional(bool)
}))
})
default = null
validation {
condition = var.warm_pool == null || var.warm_pool.pool_state == null || contains(["Stopped", "Running", "Hibernated"], var.warm_pool.pool_state)
error_message = "The warm_pool pool_state must be one of: Stopped, Running, or Hibernated."
}
}
# Scaling Policies
variable "scaling_policies" {
description = <<EOF
Map of scaling policies to create. Key is a unique name for the policy. Value is an object defining the policy.
Structure for value object:
`policy_type` = (string) "SimpleScaling", "StepScaling", or "TargetTrackingScaling". Required.
`adjustment_type` = (string) Required for Simple/Step. "ChangeInCapacity", "ExactCapacity", "PercentChangeInCapacity".
`scaling_adjustment` = (number) Required for Simple. Amount to scale.
`cooldown` = (number) Optional. Cooldown period in seconds.
`metric_aggregation_type` = (string) Optional. Default "Average". "Minimum", "Maximum", "Average".
`step_adjustments` = (list(object)) Required for Step. List of step adjustment objects { metric_interval_lower_bound, metric_interval_upper_bound, scaling_adjustment }.
`estimated_instance_warmup` = (number) Optional. Estimated time for a new instance to warm up. Required for TargetTracking if `target_tracking_configuration` isn't provided or lacks it.
`target_tracking_configuration` = (object) Required for TargetTracking. Defines the target metric. See aws_autoscaling_policy docs. Example: { predefined_metric_specification = { predefined_metric_type = "ASGAverageCPUUtilization" }, target_value = 50.0 } or { customized_metric_specification = {...} }
EOF
type = map(object({
policy_type = string
adjustment_type = optional(string)
scaling_adjustment = optional(number)
cooldown = optional(number)
metric_aggregation_type = optional(string)
estimated_instance_warmup = optional(number)
step_adjustments = optional(list(object({
metric_interval_lower_bound = optional(string)
metric_interval_upper_bound = optional(string)
scaling_adjustment = number
})))
target_tracking_configuration = optional(any) # Keeping this as any due to complexity
}))
default = {}
validation {
condition = alltrue([
for k, v in var.scaling_policies :
contains(["SimpleScaling", "StepScaling", "TargetTrackingScaling"], v.policy_type)
])
error_message = "The policy_type must be one of: SimpleScaling, StepScaling, or TargetTrackingScaling."
}
}
# Scheduled Actions
variable "scheduled_actions" {
description = <<EOF
Map of scheduled actions to create. Key is a unique name for the action. Value is an object defining the action.
Structure for value object:
`min_size` = (number) Optional. New minimum size.
`max_size` = (number) Optional. New maximum size.
`desired_capacity`= (number) Optional. New desired capacity.
`start_time` = (string) Optional. Time for the action to start, in UTC YYYY-MM-DDTHH:MM:SSZ format (or YYYY-MM-DDTHH:MM:SS+HH:MM format). Required if `recurrence` is not set.
`end_time` = (string) Optional. Time for the action to end.
`recurrence` = (string) Optional. Recurrence schedule in cron format (e.g., "0 9 * * *"). Required if `start_time` is not set.
`time_zone` = (string) Optional. Time zone for recurrence (e.g., "Etc/UTC", "America/Sao_Paulo"). Defaults to UTC.
EOF
type = any # map(object({...})) structure is complex
default = {}
}
# Lifecycle Hooks
variable "lifecycle_hooks" {
description = <<EOF
Map of lifecycle hooks to create. Key is a unique name for the hook. Value is an object defining the hook.
Structure for value object:
`lifecycle_transition` = (string) Required. "autoscaling:EC2_INSTANCE_LAUNCHING" or "autoscaling:EC2_INSTANCE_TERMINATING".
`default_result` = (string) Optional. Default "ABANDON". Can be "CONTINUE".
`heartbeat_timeout` = (number) Optional. Seconds until hook times out. Default 3600.
`notification_target_arn`= (string) Optional. ARN of the notification target (SNS topic or SQS queue).
`notification_metadata` = (string) Optional. Additional info to include in notifications.
`role_arn` = (string) Optional. ARN of the IAM role allowing ASG to publish to the notification target.
EOF
type = any # map(object({...})) structure is complex
default = {}
}
# Notifications
variable "notification_topic_arn" {
description = "The ARN of an SNS topic to send ASG notifications to."
type = string
default = null
}
variable "notification_types" {
description = "A list of notification types that trigger notifications. See AWS docs for valid types (e.g., autoscaling:EC2_INSTANCE_LAUNCH, autoscaling:EC2_INSTANCE_TERMINATE, etc.)."
type = list(string)
default = [
"autoscaling:EC2_INSTANCE_LAUNCH",
"autoscaling:EC2_INSTANCE_TERMINATE",
"autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
"autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
]
}