forked from terraform-aws-modules/terraform-aws-ec2-instance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.tf
More file actions
611 lines (526 loc) · 19.3 KB
/
variables.tf
File metadata and controls
611 lines (526 loc) · 19.3 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
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
variable "create" {
description = "Whether to create an instance"
type = bool
default = true
}
variable "name" {
description = "Name to be used on EC2 instance created"
type = string
default = ""
}
variable "region" {
description = "Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration"
type = string
default = null
}
################################################################################
# Instance
################################################################################
variable "ami" {
description = "ID of AMI to use for the instance"
type = string
default = null
}
variable "ami_ssm_parameter" {
description = "SSM parameter name for the AMI ID. For Amazon Linux AMI SSM parameters see [reference](https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-public-parameters-ami.html)"
type = string
default = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64"
}
variable "ignore_ami_changes" {
description = "Whether changes to the AMI ID changes should be ignored by Terraform. Note - changing this value will result in the replacement of the instance"
type = bool
default = false
}
variable "associate_public_ip_address" {
description = "Whether to associate a public IP address with an instance in a VPC"
type = bool
default = null
}
variable "availability_zone" {
description = "AZ to start the instance in"
type = string
default = null
}
variable "capacity_reservation_specification" {
description = "Describes an instance's Capacity Reservation targeting option"
type = object({
capacity_reservation_preference = optional(string)
capacity_reservation_target = optional(object({
capacity_reservation_id = optional(string)
capacity_reservation_resource_group_arn = optional(string)
}))
})
default = null
}
variable "cpu_options" {
description = "Defines CPU options to apply to the instance at launch time."
type = object({
amd_sev_snp = optional(string)
core_count = optional(number)
threads_per_core = optional(number)
})
default = null
}
variable "cpu_credits" {
description = "The credit option for CPU usage (unlimited or standard)"
type = string
default = null
}
variable "disable_api_termination" {
description = "If true, enables EC2 Instance Termination Protection"
type = bool
default = null
}
variable "disable_api_stop" {
description = "If true, enables EC2 Instance Stop Protection"
type = bool
default = null
}
variable "ebs_optimized" {
description = "If true, the launched EC2 instance will be EBS-optimized"
type = bool
default = null
}
variable "enclave_options_enabled" {
description = "Whether Nitro Enclaves will be enabled on the instance. Defaults to `false`"
type = bool
default = null
}
variable "enable_primary_ipv6" {
description = "Whether to assign a primary IPv6 Global Unicast Address (GUA) to the instance when launched in a dual-stack or IPv6-only subnet"
type = bool
default = null
}
variable "ephemeral_block_device" {
description = "Customize Ephemeral (also known as Instance Store) volumes on the instance"
type = map(object({
device_name = string
no_device = optional(bool)
virtual_name = optional(string)
}))
default = null
}
variable "get_password_data" {
description = "If true, wait for password data to become available and retrieve it"
type = bool
default = null
}
variable "hibernation" {
description = "If true, the launched EC2 instance will support hibernation"
type = bool
default = null
}
variable "host_id" {
description = "ID of a dedicated host that the instance will be assigned to. Use when an instance is to be launched on a specific dedicated host"
type = string
default = null
}
variable "host_resource_group_arn" {
description = "ARN of the host resource group in which to launch the instances. If you specify an ARN, omit the `tenancy` parameter or set it to `host`"
type = string
default = null
}
variable "iam_instance_profile" {
description = "IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile"
type = string
default = null
}
variable "instance_initiated_shutdown_behavior" {
description = "Shutdown behavior for the instance. Amazon defaults this to stop for EBS-backed instances and terminate for instance-store instances. Cannot be set on instance-store instance" # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingInstanceInitiatedShutdownBehavior
type = string
default = null
}
variable "instance_market_options" {
description = "The market (purchasing) option for the instance. If set, overrides the `create_spot_instance` variable"
type = object({
market_type = optional(string)
spot_options = optional(object({
instance_interruption_behavior = optional(string)
max_price = optional(string)
spot_instance_type = optional(string)
valid_until = optional(string)
}))
})
default = null
}
variable "instance_type" {
description = "The type of instance to start"
type = string
default = "t3.micro"
}
variable "ipv6_address_count" {
description = "A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet"
type = number
default = null
}
variable "ipv6_addresses" {
description = "Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface"
type = list(string)
default = null
}
variable "key_name" {
description = "Key name of the Key Pair to use for the instance; which can be managed using the `aws_key_pair` resource"
type = string
default = null
}
variable "launch_template" {
description = "Specifies a Launch Template to configure the instance. Parameters configured on this resource will override the corresponding parameters in the Launch Template"
type = object({
id = optional(string)
name = optional(string)
version = optional(string)
})
default = null
}
variable "maintenance_options" {
description = "The maintenance options for the instance"
type = object({
auto_recovery = optional(string)
})
default = null
}
variable "metadata_options" {
description = "Customize the metadata options of the instance"
type = object({
http_endpoint = optional(string, "enabled")
http_protocol_ipv6 = optional(string)
http_put_response_hop_limit = optional(number, 1)
http_tokens = optional(string, "required")
instance_metadata_tags = optional(string)
})
default = {
http_endpoint = "enabled"
http_put_response_hop_limit = 1
http_tokens = "required"
}
}
variable "monitoring" {
description = "If true, the launched EC2 instance will have detailed monitoring enabled"
type = bool
default = null
}
variable "network_interface" {
description = "Customize network interfaces to be attached at instance boot time"
type = map(object({
delete_on_termination = optional(bool)
device_index = optional(number) # Will fall back to use map key as device index
network_card_index = optional(number)
network_interface_id = string
}))
default = null
}
variable "placement_group" {
description = "The Placement Group to start the instance in"
type = string
default = null
}
variable "placement_partition_number" {
description = "Number of the partition the instance is in. Valid only if the `aws_placement_group` resource's `strategy` argument is set to `partition`"
type = number
default = null
}
variable "private_dns_name_options" {
description = "Customize the private DNS name options of the instance"
type = object({
enable_resource_name_dns_a_record = optional(bool)
enable_resource_name_dns_aaaa_record = optional(bool)
hostname_type = optional(string)
})
default = null
}
variable "private_ip" {
description = "Private IP address to associate with the instance in a VPC"
type = string
default = null
}
variable "root_block_device" {
description = "Customize details about the root block device of the instance. See Block Devices below for details"
type = object({
delete_on_termination = optional(bool)
encrypted = optional(bool)
iops = optional(number)
kms_key_id = optional(string)
tags = optional(map(string))
throughput = optional(number)
size = optional(number)
type = optional(string)
})
default = null
}
variable "secondary_private_ips" {
description = "A list of secondary private IPv4 addresses to assign to the instance's primary network interface (eth0) in a VPC. Can only be assigned to the primary network interface (eth0) attached at instance creation, not a pre-existing network interface i.e. referenced in a `network_interface block`"
type = list(string)
default = null
}
variable "source_dest_check" {
description = "Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs"
type = bool
default = null
}
variable "subnet_id" {
description = "The VPC Subnet ID to launch in"
type = string
default = null
}
variable "tags" {
description = "A mapping of tags to assign to the resource"
type = map(string)
default = {}
}
variable "instance_tags" {
description = "Additional tags for the instance"
type = map(string)
default = {}
}
variable "tenancy" {
description = "The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host"
type = string
default = null
}
variable "user_data" {
description = "The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see user_data_base64 instead"
type = string
default = null
}
variable "user_data_base64" {
description = "Can be used instead of user_data to pass base64-encoded binary data directly. Use this instead of user_data whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption"
type = string
default = null
}
variable "user_data_replace_on_change" {
description = "When used in combination with user_data or user_data_base64 will trigger a destroy and recreate when set to true. Defaults to false if not set"
type = bool
default = null
}
variable "volume_tags" {
description = "A mapping of tags to assign to the devices created by the instance at launch time"
type = map(string)
default = {}
}
variable "enable_volume_tags" {
description = "Whether to enable volume tags (if enabled it conflicts with root_block_device tags)"
type = bool
default = true
}
variable "vpc_security_group_ids" {
description = "A list of security group IDs to associate with"
type = list(string)
default = []
}
variable "timeouts" {
description = "Define maximum timeout for creating, updating, and deleting EC2 instance resources"
type = object({
create = optional(string)
update = optional(string)
delete = optional(string)
})
default = null
}
################################################################################
# Spot Instance Request
################################################################################
variable "create_spot_instance" {
description = "Depicts if the instance is a spot instance"
type = bool
default = false
}
variable "spot_instance_interruption_behavior" {
description = "Indicates Spot instance behavior when it is interrupted. Valid values are `terminate`, `stop`, or `hibernate`"
type = string
default = null
}
variable "spot_launch_group" {
description = "A launch group is a group of spot instances that launch together and terminate together. If left empty instances are launched and terminated individually"
type = string
default = null
}
variable "spot_price" {
description = "The maximum price to request on the spot market. Defaults to on-demand price"
type = string
default = null
}
variable "spot_type" {
description = "If set to one-time, after the instance is terminated, the spot request will be closed. Default `persistent`"
type = string
default = null
}
variable "spot_wait_for_fulfillment" {
description = "If set, Terraform will wait for the Spot Request to be fulfilled, and will throw an error if the timeout of 10m is reached"
type = bool
default = null
}
variable "spot_valid_from" {
description = "The start date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ)"
type = string
default = null
}
variable "spot_valid_until" {
description = "The end date and time of the request, in UTC RFC3339 format(for example, YYYY-MM-DDTHH:MM:SSZ)"
type = string
default = null
}
################################################################################
# EBS Volume(s)
################################################################################
variable "ebs_volumes" {
description = "Additional EBS volumes to attach to the instance"
type = map(object({
encrypted = optional(bool)
final_snapshot = optional(bool)
iops = optional(number)
kms_key_id = optional(string)
multi_attach_enabled = optional(bool)
outpost_arn = optional(string)
size = optional(number)
snapshot_id = optional(string)
tags = optional(map(string), {})
throughput = optional(number)
type = optional(string, "gp3")
# Attachment
device_name = optional(string) # Will fall back to use map key as device name
force_detach = optional(bool)
skip_destroy = optional(bool)
stop_instance_before_detaching = optional(bool)
}))
default = null
}
################################################################################
# IAM Role / Instance Profile
################################################################################
variable "create_iam_instance_profile" {
description = "Determines whether an IAM instance profile is created or to use an existing IAM instance profile"
type = bool
default = false
}
variable "iam_role_name" {
description = "Name to use on IAM role created"
type = string
default = null
}
variable "iam_role_use_name_prefix" {
description = "Determines whether the IAM role name (`iam_role_name` or `name`) is used as a prefix"
type = bool
default = true
}
variable "iam_role_path" {
description = "IAM role path"
type = string
default = null
}
variable "iam_role_description" {
description = "Description of the role"
type = string
default = null
}
variable "iam_role_permissions_boundary" {
description = "ARN of the policy that is used to set the permissions boundary for the IAM role"
type = string
default = null
}
variable "iam_role_policies" {
description = "Policies attached to the IAM role"
type = map(string)
default = {}
}
variable "iam_role_tags" {
description = "A map of additional tags to add to the IAM role/profile created"
type = map(string)
default = {}
}
################################################################################
# Security Group
################################################################################
variable "create_security_group" {
description = "Determines whether a security group will be created"
type = bool
default = true
}
variable "security_group_name" {
description = "Name to use on security group created"
type = string
default = null
}
variable "security_group_use_name_prefix" {
description = "Determines whether the security group name (`security_group_name` or `name`) is used as a prefix"
type = bool
default = true
}
variable "security_group_description" {
description = "Description of the security group"
type = string
default = null
}
variable "security_group_vpc_id" {
description = "VPC ID to create the security group in. If not set, the security group will be created in the default VPC"
type = string
default = null
}
variable "security_group_tags" {
description = "A map of additional tags to add to the security group created"
type = map(string)
default = {}
}
variable "security_group_egress_rules" {
description = "Egress rules to add to the security group"
type = map(object({
cidr_ipv4 = optional(string)
cidr_ipv6 = optional(string)
description = optional(string)
from_port = optional(number)
ip_protocol = optional(string, "tcp")
prefix_list_id = optional(string)
referenced_security_group_id = optional(string)
tags = optional(map(string), {})
to_port = optional(number)
}))
default = {
ipv4_default = {
cidr_ipv4 = "0.0.0.0/0"
description = "Allow all IPv4 traffic"
ip_protocol = "-1"
}
ipv6_default = {
cidr_ipv6 = "::/0"
description = "Allow all IPv6 traffic"
ip_protocol = "-1"
}
}
}
variable "security_group_ingress_rules" {
description = "Ingress rules to add to the security group"
type = map(object({
cidr_ipv4 = optional(string)
cidr_ipv6 = optional(string)
description = optional(string)
from_port = optional(number)
ip_protocol = optional(string, "tcp")
prefix_list_id = optional(string)
referenced_security_group_id = optional(string)
tags = optional(map(string), {})
to_port = optional(number)
}))
default = null
}
################################################################################
# Elastic IP
################################################################################
variable "create_eip" {
description = "Determines whether a public EIP will be created and associated with the instance."
type = bool
default = false
}
variable "eip_domain" {
description = "Indicates if this EIP is for use in VPC"
type = string
default = "vpc"
}
variable "eip_tags" {
description = "A map of additional tags to add to the eip"
type = map(string)
default = {}
}
variable "putin_khuylo" {
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
type = bool
default = true
}