@@ -59,8 +59,8 @@ module "ec2_complete" {
59
59
threads_per_core = 1
60
60
}
61
61
enable_volume_tags = false
62
- root_block_device = [
63
- {
62
+ root_block_device = {
63
+ main = {
64
64
encrypted = true
65
65
volume_type = " gp3"
66
66
throughput = 200
@@ -69,11 +69,10 @@ module "ec2_complete" {
69
69
Name = " my-root-block"
70
70
}
71
71
},
72
- ]
72
+ }
73
73
74
- ebs_block_device = [
75
- {
76
- device_name = " /dev/sdf"
74
+ ebs_volumes = {
75
+ " /dev/sdf" = {
77
76
volume_type = " gp3"
78
77
volume_size = 5
79
78
throughput = 200
@@ -83,7 +82,7 @@ module "ec2_complete" {
83
82
MountPoint = " /mnt/data"
84
83
}
85
84
}
86
- ]
85
+ }
87
86
88
87
tags = local. tags
89
88
}
@@ -93,13 +92,12 @@ module "ec2_network_interface" {
93
92
94
93
name = " ${ local . name } -network-interface"
95
94
96
- network_interface = [
97
- {
98
- device_index = 0
95
+ network_interface = {
96
+ 0 = {
99
97
network_interface_id = aws_network_interface.this.id
100
98
delete_on_termination = false
101
99
}
102
- ]
100
+ }
103
101
104
102
tags = local. tags
105
103
}
@@ -109,8 +107,7 @@ module "ec2_metadata_options" {
109
107
110
108
name = " ${ local . name } -metadata-options"
111
109
112
- subnet_id = element (module. vpc . private_subnets , 0 )
113
- vpc_security_group_ids = [module . security_group . security_group_id ]
110
+ subnet_id = element (module. vpc . private_subnets , 0 )
114
111
115
112
metadata_options = {
116
113
http_endpoint = " enabled"
@@ -130,7 +127,6 @@ module "ec2_t2_unlimited" {
130
127
instance_type = " t2.micro"
131
128
cpu_credits = " unlimited"
132
129
subnet_id = element (module. vpc . private_subnets , 0 )
133
- vpc_security_group_ids = [module . security_group . security_group_id ]
134
130
associate_public_ip_address = true
135
131
136
132
maintenance_options = {
@@ -148,7 +144,6 @@ module "ec2_t3_unlimited" {
148
144
instance_type = " t3.micro"
149
145
cpu_credits = " unlimited"
150
146
subnet_id = element (module. vpc . private_subnets , 0 )
151
- vpc_security_group_ids = [module . security_group . security_group_id ]
152
147
associate_public_ip_address = true
153
148
154
149
tags = local. tags
@@ -171,11 +166,10 @@ module "ec2_ignore_ami_changes" {
171
166
172
167
ignore_ami_changes = true
173
168
174
- ami = data. aws_ami . amazon_linux . id
175
- instance_type = " t2.micro"
176
- availability_zone = element (module. vpc . azs , 0 )
177
- subnet_id = element (module. vpc . private_subnets , 0 )
178
- vpc_security_group_ids = [module . security_group . security_group_id ]
169
+ ami = data. aws_ami . amazon_linux . id
170
+ instance_type = " t2.micro"
171
+ availability_zone = element (module. vpc . azs , 0 )
172
+ subnet_id = element (module. vpc . private_subnets , 0 )
179
173
180
174
tags = local. tags
181
175
}
@@ -190,8 +184,8 @@ locals {
190
184
instance_type = " t3.micro"
191
185
availability_zone = element (module. vpc . azs , 0 )
192
186
subnet_id = element (module. vpc . private_subnets , 0 )
193
- root_block_device = [
194
- {
187
+ root_block_device = {
188
+ main = {
195
189
encrypted = true
196
190
volume_type = " gp3"
197
191
throughput = 200
@@ -200,19 +194,19 @@ locals {
200
194
Name = " my-root-block"
201
195
}
202
196
}
203
- ]
197
+ }
204
198
}
205
199
two = {
206
200
instance_type = " t3.small"
207
201
availability_zone = element (module. vpc . azs , 1 )
208
202
subnet_id = element (module. vpc . private_subnets , 1 )
209
- root_block_device = [
210
- {
203
+ root_block_device = {
204
+ main = {
211
205
encrypted = true
212
206
volume_type = " gp2"
213
207
volume_size = 50
214
208
}
215
- ]
209
+ }
216
210
}
217
211
three = {
218
212
instance_type = " t3.medium"
@@ -229,13 +223,12 @@ module "ec2_multiple" {
229
223
230
224
name = " ${ local . name } -multi-${ each . key } "
231
225
232
- instance_type = each. value . instance_type
233
- availability_zone = each. value . availability_zone
234
- subnet_id = each. value . subnet_id
235
- vpc_security_group_ids = [module . security_group . security_group_id ]
226
+ instance_type = each. value . instance_type
227
+ availability_zone = each. value . availability_zone
228
+ subnet_id = each. value . subnet_id
236
229
237
230
enable_volume_tags = false
238
- root_block_device = lookup (each. value , " root_block_device" , [] )
231
+ root_block_device = try (each. value . root_block_device , null )
239
232
240
233
tags = local. tags
241
234
}
@@ -256,10 +249,9 @@ module "ec2_spot_instance" {
256
249
associate_public_ip_address = true
257
250
258
251
# Spot request specific attributes
259
- spot_price = " 0.1"
260
- spot_wait_for_fulfillment = true
261
- spot_type = " persistent"
262
- spot_instance_interruption_behavior = " terminate"
252
+ spot_price = " 0.1"
253
+ spot_wait_for_fulfillment = true
254
+ spot_type = " persistent"
263
255
# End spot request specific attributes
264
256
265
257
user_data_base64 = base64encode (local. user_data )
@@ -270,28 +262,27 @@ module "ec2_spot_instance" {
270
262
}
271
263
272
264
enable_volume_tags = false
273
- root_block_device = [
274
- {
265
+ root_block_device = {
266
+ main = {
275
267
encrypted = true
276
268
volume_type = " gp3"
277
269
throughput = 200
278
270
volume_size = 50
279
271
tags = {
280
272
Name = " my-root-block"
281
273
}
282
- },
283
- ]
274
+ }
275
+ }
284
276
285
- ebs_block_device = [
286
- {
287
- device_name = " /dev/sdf"
277
+ ebs_volumes = {
278
+ " /dev/sdf" = {
288
279
volume_type = " gp3"
289
280
volume_size = 5
290
281
throughput = 200
291
282
encrypted = true
292
283
# kms_key_id = aws_kms_key.this.arn # you must grant the AWSServiceRoleForEC2Spot service-linked role access to any custom KMS keys
293
284
}
294
- ]
285
+ }
295
286
296
287
tags = local. tags
297
288
}
@@ -305,10 +296,8 @@ module "ec2_open_capacity_reservation" {
305
296
306
297
name = " ${ local . name } -open-capacity-reservation"
307
298
308
- ami = data. aws_ami . amazon_linux . id
309
299
instance_type = " t3.micro"
310
300
subnet_id = element (module. vpc . private_subnets , 0 )
311
- vpc_security_group_ids = [module . security_group . security_group_id ]
312
301
associate_public_ip_address = false
313
302
314
303
capacity_reservation_specification = {
@@ -325,10 +314,8 @@ module "ec2_targeted_capacity_reservation" {
325
314
326
315
name = " ${ local . name } -targeted-capacity-reservation"
327
316
328
- ami = data. aws_ami . amazon_linux . id
329
317
instance_type = " t3.micro"
330
318
subnet_id = element (module. vpc . private_subnets , 0 )
331
- vpc_security_group_ids = [module . security_group . security_group_id ]
332
319
associate_public_ip_address = false
333
320
334
321
capacity_reservation_specification = {
@@ -365,11 +352,9 @@ module "ec2_cpu_options" {
365
352
366
353
name = " ${ local . name } -cpu-options"
367
354
368
- ami = data. aws_ami . amazon_linux_23 . id
369
355
instance_type = " c6a.xlarge" # used to set core count below and test amd_sev_snp attribute
370
356
availability_zone = element (module. vpc . azs , 0 )
371
357
subnet_id = element (module. vpc . private_subnets , 0 )
372
- vpc_security_group_ids = [module . security_group . security_group_id ]
373
358
placement_group = aws_placement_group. web . id
374
359
associate_public_ip_address = true
375
360
disable_api_stop = false
@@ -389,22 +374,20 @@ module "ec2_cpu_options" {
389
374
amd_sev_snp = " enabled"
390
375
}
391
376
enable_volume_tags = false
392
- root_block_device = [
393
- {
377
+ root_block_device = {
378
+ main = {
394
379
encrypted = true
395
380
volume_type = " gp3"
396
381
throughput = 200
397
382
volume_size = 50
398
383
tags = {
399
384
Name = " my-root-block"
400
385
}
401
- },
402
- ]
386
+ }
387
+ }
403
388
404
- ebs_block_device = [
405
- {
406
- device_name = " /dev/sdf"
407
- volume_type = " gp3"
389
+ ebs_volumes = {
390
+ " /dev/sdf" = {
408
391
volume_size = 5
409
392
throughput = 200
410
393
encrypted = true
@@ -413,7 +396,7 @@ module "ec2_cpu_options" {
413
396
MountPoint = " /mnt/data"
414
397
}
415
398
}
416
- ]
399
+ }
417
400
418
401
instance_tags = { Persistence = " 09:00-18:00" }
419
402
@@ -426,7 +409,7 @@ module "ec2_cpu_options" {
426
409
427
410
module "vpc" {
428
411
source = " terraform-aws-modules/vpc/aws"
429
- version = " ~> 5 .0"
412
+ version = " ~> 6 .0"
430
413
431
414
name = local. name
432
415
cidr = local. vpc_cidr
@@ -441,34 +424,19 @@ module "vpc" {
441
424
data "aws_ami" "amazon_linux" {
442
425
most_recent = true
443
426
owners = [" amazon" ]
444
-
445
- filter {
446
- name = " name"
447
- values = [" amzn-ami-hvm-*-x86_64-gp2" ]
448
- }
449
- }
450
-
451
- data "aws_ami" "amazon_linux_23" {
452
- most_recent = true
453
- owners = [" amazon" ]
454
-
455
- filter {
456
- name = " name"
457
- values = [" al2023-ami-2023*-x86_64" ]
458
- }
427
+ name_regex = " ^al2023-ami-2023.*-x86_64"
459
428
}
460
429
461
430
module "security_group" {
462
431
source = " terraform-aws-modules/security-group/aws"
463
- version = " ~> 4 .0"
432
+ version = " ~> 5 .0"
464
433
465
434
name = local. name
466
435
description = " Security group for example usage with EC2 instance"
467
436
vpc_id = module. vpc . vpc_id
468
437
469
438
ingress_cidr_blocks = [" 0.0.0.0/0" ]
470
439
ingress_rules = [" http-80-tcp" , " all-icmp" ]
471
- egress_rules = [" all-all" ]
472
440
473
441
tags = local. tags
474
442
}
0 commit comments