@@ -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
}
@@ -308,7 +299,6 @@ module "ec2_open_capacity_reservation" {
308
299
ami = data. aws_ami . amazon_linux . id
309
300
instance_type = " t3.micro"
310
301
subnet_id = element (module. vpc . private_subnets , 0 )
311
- vpc_security_group_ids = [module . security_group . security_group_id ]
312
302
associate_public_ip_address = false
313
303
314
304
capacity_reservation_specification = {
@@ -328,7 +318,6 @@ module "ec2_targeted_capacity_reservation" {
328
318
ami = data. aws_ami . amazon_linux . id
329
319
instance_type = " t3.micro"
330
320
subnet_id = element (module. vpc . private_subnets , 0 )
331
- vpc_security_group_ids = [module . security_group . security_group_id ]
332
321
associate_public_ip_address = false
333
322
334
323
capacity_reservation_specification = {
@@ -369,7 +358,6 @@ module "ec2_cpu_options" {
369
358
instance_type = " c6a.xlarge" # used to set core count below and test amd_sev_snp attribute
370
359
availability_zone = element (module. vpc . azs , 0 )
371
360
subnet_id = element (module. vpc . private_subnets , 0 )
372
- vpc_security_group_ids = [module . security_group . security_group_id ]
373
361
placement_group = aws_placement_group. web . id
374
362
associate_public_ip_address = true
375
363
disable_api_stop = false
@@ -389,22 +377,20 @@ module "ec2_cpu_options" {
389
377
amd_sev_snp = " enabled"
390
378
}
391
379
enable_volume_tags = false
392
- root_block_device = [
393
- {
380
+ root_block_device = {
381
+ main = {
394
382
encrypted = true
395
383
volume_type = " gp3"
396
384
throughput = 200
397
385
volume_size = 50
398
386
tags = {
399
387
Name = " my-root-block"
400
388
}
401
- },
402
- ]
389
+ }
390
+ }
403
391
404
- ebs_block_device = [
405
- {
406
- device_name = " /dev/sdf"
407
- volume_type = " gp3"
392
+ ebs_volumes = {
393
+ " /dev/sdf" = {
408
394
volume_size = 5
409
395
throughput = 200
410
396
encrypted = true
@@ -413,7 +399,7 @@ module "ec2_cpu_options" {
413
399
MountPoint = " /mnt/data"
414
400
}
415
401
}
416
- ]
402
+ }
417
403
418
404
instance_tags = { Persistence = " 09:00-18:00" }
419
405
@@ -426,7 +412,7 @@ module "ec2_cpu_options" {
426
412
427
413
module "vpc" {
428
414
source = " terraform-aws-modules/vpc/aws"
429
- version = " ~> 5 .0"
415
+ version = " ~> 6 .0"
430
416
431
417
name = local. name
432
418
cidr = local. vpc_cidr
@@ -466,9 +452,7 @@ module "security_group" {
466
452
description = " Security group for example usage with EC2 instance"
467
453
vpc_id = module. vpc . vpc_id
468
454
469
- ingress_cidr_blocks = [" 0.0.0.0/0" ]
470
- ingress_rules = [" http-80-tcp" , " all-icmp" ]
471
- egress_rules = [" all-all" ]
455
+ ingress_rules = [" http-80-tcp" , " all-icmp" ]
472
456
473
457
tags = local. tags
474
458
}
0 commit comments