@@ -59,8 +59,8 @@ module "ec2_complete" {
5959 threads_per_core = 1
6060 }
6161 enable_volume_tags = false
62- root_block_device = [
63- {
62+ root_block_device = {
63+ main = {
6464 encrypted = true
6565 volume_type = " gp3"
6666 throughput = 200
@@ -69,11 +69,10 @@ module "ec2_complete" {
6969 Name = " my-root-block"
7070 }
7171 },
72- ]
72+ }
7373
74- ebs_block_device = [
75- {
76- device_name = " /dev/sdf"
74+ ebs_volumes = {
75+ " /dev/sdf" = {
7776 volume_type = " gp3"
7877 volume_size = 5
7978 throughput = 200
@@ -83,7 +82,7 @@ module "ec2_complete" {
8382 MountPoint = " /mnt/data"
8483 }
8584 }
86- ]
85+ }
8786
8887 tags = local. tags
8988}
@@ -93,13 +92,12 @@ module "ec2_network_interface" {
9392
9493 name = " ${ local . name } -network-interface"
9594
96- network_interface = [
97- {
98- device_index = 0
95+ network_interface = {
96+ 0 = {
9997 network_interface_id = aws_network_interface.this.id
10098 delete_on_termination = false
10199 }
102- ]
100+ }
103101
104102 tags = local. tags
105103}
@@ -109,8 +107,7 @@ module "ec2_metadata_options" {
109107
110108 name = " ${ local . name } -metadata-options"
111109
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 )
114111
115112 metadata_options = {
116113 http_endpoint = " enabled"
@@ -130,7 +127,6 @@ module "ec2_t2_unlimited" {
130127 instance_type = " t2.micro"
131128 cpu_credits = " unlimited"
132129 subnet_id = element (module. vpc . private_subnets , 0 )
133- vpc_security_group_ids = [module . security_group . security_group_id ]
134130 associate_public_ip_address = true
135131
136132 maintenance_options = {
@@ -148,7 +144,6 @@ module "ec2_t3_unlimited" {
148144 instance_type = " t3.micro"
149145 cpu_credits = " unlimited"
150146 subnet_id = element (module. vpc . private_subnets , 0 )
151- vpc_security_group_ids = [module . security_group . security_group_id ]
152147 associate_public_ip_address = true
153148
154149 tags = local. tags
@@ -171,11 +166,10 @@ module "ec2_ignore_ami_changes" {
171166
172167 ignore_ami_changes = true
173168
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 )
179173
180174 tags = local. tags
181175}
@@ -190,8 +184,8 @@ locals {
190184 instance_type = " t3.micro"
191185 availability_zone = element (module. vpc . azs , 0 )
192186 subnet_id = element (module. vpc . private_subnets , 0 )
193- root_block_device = [
194- {
187+ root_block_device = {
188+ main = {
195189 encrypted = true
196190 volume_type = " gp3"
197191 throughput = 200
@@ -200,19 +194,19 @@ locals {
200194 Name = " my-root-block"
201195 }
202196 }
203- ]
197+ }
204198 }
205199 two = {
206200 instance_type = " t3.small"
207201 availability_zone = element (module. vpc . azs , 1 )
208202 subnet_id = element (module. vpc . private_subnets , 1 )
209- root_block_device = [
210- {
203+ root_block_device = {
204+ main = {
211205 encrypted = true
212206 volume_type = " gp2"
213207 volume_size = 50
214208 }
215- ]
209+ }
216210 }
217211 three = {
218212 instance_type = " t3.medium"
@@ -229,13 +223,12 @@ module "ec2_multiple" {
229223
230224 name = " ${ local . name } -multi-${ each . key } "
231225
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
236229
237230 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 )
239232
240233 tags = local. tags
241234}
@@ -256,10 +249,9 @@ module "ec2_spot_instance" {
256249 associate_public_ip_address = true
257250
258251 # 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"
263255 # End spot request specific attributes
264256
265257 user_data_base64 = base64encode (local. user_data )
@@ -270,28 +262,27 @@ module "ec2_spot_instance" {
270262 }
271263
272264 enable_volume_tags = false
273- root_block_device = [
274- {
265+ root_block_device = {
266+ main = {
275267 encrypted = true
276268 volume_type = " gp3"
277269 throughput = 200
278270 volume_size = 50
279271 tags = {
280272 Name = " my-root-block"
281273 }
282- },
283- ]
274+ }
275+ }
284276
285- ebs_block_device = [
286- {
287- device_name = " /dev/sdf"
277+ ebs_volumes = {
278+ " /dev/sdf" = {
288279 volume_type = " gp3"
289280 volume_size = 5
290281 throughput = 200
291282 encrypted = true
292283 # kms_key_id = aws_kms_key.this.arn # you must grant the AWSServiceRoleForEC2Spot service-linked role access to any custom KMS keys
293284 }
294- ]
285+ }
295286
296287 tags = local. tags
297288}
@@ -308,7 +299,6 @@ module "ec2_open_capacity_reservation" {
308299 ami = data. aws_ami . amazon_linux . id
309300 instance_type = " t3.micro"
310301 subnet_id = element (module. vpc . private_subnets , 0 )
311- vpc_security_group_ids = [module . security_group . security_group_id ]
312302 associate_public_ip_address = false
313303
314304 capacity_reservation_specification = {
@@ -328,7 +318,6 @@ module "ec2_targeted_capacity_reservation" {
328318 ami = data. aws_ami . amazon_linux . id
329319 instance_type = " t3.micro"
330320 subnet_id = element (module. vpc . private_subnets , 0 )
331- vpc_security_group_ids = [module . security_group . security_group_id ]
332321 associate_public_ip_address = false
333322
334323 capacity_reservation_specification = {
@@ -369,7 +358,6 @@ module "ec2_cpu_options" {
369358 instance_type = " c6a.xlarge" # used to set core count below and test amd_sev_snp attribute
370359 availability_zone = element (module. vpc . azs , 0 )
371360 subnet_id = element (module. vpc . private_subnets , 0 )
372- vpc_security_group_ids = [module . security_group . security_group_id ]
373361 placement_group = aws_placement_group. web . id
374362 associate_public_ip_address = true
375363 disable_api_stop = false
@@ -389,22 +377,20 @@ module "ec2_cpu_options" {
389377 amd_sev_snp = " enabled"
390378 }
391379 enable_volume_tags = false
392- root_block_device = [
393- {
380+ root_block_device = {
381+ main = {
394382 encrypted = true
395383 volume_type = " gp3"
396384 throughput = 200
397385 volume_size = 50
398386 tags = {
399387 Name = " my-root-block"
400388 }
401- },
402- ]
389+ }
390+ }
403391
404- ebs_block_device = [
405- {
406- device_name = " /dev/sdf"
407- volume_type = " gp3"
392+ ebs_volumes = {
393+ " /dev/sdf" = {
408394 volume_size = 5
409395 throughput = 200
410396 encrypted = true
@@ -413,7 +399,7 @@ module "ec2_cpu_options" {
413399 MountPoint = " /mnt/data"
414400 }
415401 }
416- ]
402+ }
417403
418404 instance_tags = { Persistence = " 09:00-18:00" }
419405
@@ -426,7 +412,7 @@ module "ec2_cpu_options" {
426412
427413module "vpc" {
428414 source = " terraform-aws-modules/vpc/aws"
429- version = " ~> 5 .0"
415+ version = " ~> 6 .0"
430416
431417 name = local. name
432418 cidr = local. vpc_cidr
@@ -466,9 +452,7 @@ module "security_group" {
466452 description = " Security group for example usage with EC2 instance"
467453 vpc_id = module. vpc . vpc_id
468454
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" ]
472456
473457 tags = local. tags
474458}
0 commit comments