Skip to content

Commit 976ad60

Browse files
committed
feat: use a map for root_block_device instead of list
1 parent 4f8387d commit 976ad60

File tree

5 files changed

+47
-57
lines changed

5 files changed

+47
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ No modules.
240240
| <a name="input_private_dns_name_options"></a> [private\_dns\_name\_options](#input\_private\_dns\_name\_options) | Customize the private DNS name options of the instance | `map(string)` | `{}` | no |
241241
| <a name="input_private_ip"></a> [private\_ip](#input\_private\_ip) | Private IP address to associate with the instance in a VPC | `string` | `null` | no |
242242
| <a name="input_putin_khuylo"></a> [putin\_khuylo](#input\_putin\_khuylo) | Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! | `bool` | `true` | no |
243-
| <a name="input_root_block_device"></a> [root\_block\_device](#input\_root\_block\_device) | Customize details about the root block device of the instance. See Block Devices below for details | `list(any)` | `[]` | no |
243+
| <a name="input_root_block_device"></a> [root\_block\_device](#input\_root\_block\_device) | Customize details about the root block device of the instance. See Block Devices below for details | `any` | `{}` | no |
244244
| <a name="input_secondary_private_ips"></a> [secondary\_private\_ips](#input\_secondary\_private\_ips) | 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` | `list(string)` | `null` | no |
245245
| <a name="input_source_dest_check"></a> [source\_dest\_check](#input\_source\_dest\_check) | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs | `bool` | `null` | no |
246246
| <a name="input_spot_block_duration_minutes"></a> [spot\_block\_duration\_minutes](#input\_spot\_block\_duration\_minutes) | The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360) | `number` | `null` | no |

examples/complete/main.tf

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@ module "ec2_complete" {
5959
threads_per_core = 1
6060
}
6161
enable_volume_tags = false
62-
root_block_device = [
63-
{
64-
encrypted = true
65-
volume_type = "gp3"
66-
throughput = 200
67-
volume_size = 50
68-
tags = {
69-
Name = "my-root-block"
70-
}
71-
},
72-
]
62+
root_block_device = {
63+
encrypted = true
64+
volume_type = "gp3"
65+
throughput = 200
66+
volume_size = 50
67+
tags = {
68+
Name = "my-root-block"
69+
}
70+
}
7371

7472
ebs_block_device = [
7573
{
@@ -190,29 +188,25 @@ locals {
190188
instance_type = "t3.micro"
191189
availability_zone = element(module.vpc.azs, 0)
192190
subnet_id = element(module.vpc.private_subnets, 0)
193-
root_block_device = [
194-
{
195-
encrypted = true
196-
volume_type = "gp3"
197-
throughput = 200
198-
volume_size = 50
199-
tags = {
200-
Name = "my-root-block"
201-
}
191+
root_block_device = {
192+
encrypted = true
193+
volume_type = "gp3"
194+
throughput = 200
195+
volume_size = 50
196+
tags = {
197+
Name = "my-root-block"
202198
}
203-
]
199+
}
204200
}
205201
two = {
206202
instance_type = "t3.small"
207203
availability_zone = element(module.vpc.azs, 1)
208204
subnet_id = element(module.vpc.private_subnets, 1)
209-
root_block_device = [
210-
{
211-
encrypted = true
212-
volume_type = "gp2"
213-
volume_size = 50
214-
}
215-
]
205+
root_block_device = {
206+
encrypted = true
207+
volume_type = "gp2"
208+
volume_size = 50
209+
}
216210
}
217211
three = {
218212
instance_type = "t3.medium"
@@ -270,17 +264,15 @@ module "ec2_spot_instance" {
270264
}
271265

272266
enable_volume_tags = false
273-
root_block_device = [
274-
{
275-
encrypted = true
276-
volume_type = "gp3"
277-
throughput = 200
278-
volume_size = 50
279-
tags = {
280-
Name = "my-root-block"
281-
}
282-
},
283-
]
267+
root_block_device = {
268+
encrypted = true
269+
volume_type = "gp3"
270+
throughput = 200
271+
volume_size = 50
272+
tags = {
273+
Name = "my-root-block"
274+
}
275+
}
284276

285277
ebs_block_device = [
286278
{
@@ -389,17 +381,15 @@ module "ec2_cpu_options" {
389381
amd_sev_snp = "enabled"
390382
}
391383
enable_volume_tags = false
392-
root_block_device = [
393-
{
394-
encrypted = true
395-
volume_type = "gp3"
396-
throughput = 200
397-
volume_size = 50
398-
tags = {
399-
Name = "my-root-block"
400-
}
401-
},
402-
]
384+
root_block_device = {
385+
encrypted = true
386+
volume_type = "gp3"
387+
throughput = 200
388+
volume_size = 50
389+
tags = {
390+
Name = "my-root-block"
391+
}
392+
}
403393

404394
ebs_block_device = [
405395
{

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ resource "aws_instance" "this" {
7676
}
7777

7878
dynamic "root_block_device" {
79-
for_each = var.root_block_device
79+
for_each = length(var.root_block_device) > 0 ? [var.root_block_device] : []
8080

8181
content {
8282
delete_on_termination = try(root_block_device.value.delete_on_termination, null)
@@ -254,7 +254,7 @@ resource "aws_instance" "ignore_ami" {
254254
}
255255

256256
dynamic "root_block_device" {
257-
for_each = var.root_block_device
257+
for_each = length(var.root_block_device) > 0 ? [var.root_block_device] : []
258258

259259
content {
260260
delete_on_termination = try(root_block_device.value.delete_on_termination, null)
@@ -448,7 +448,7 @@ resource "aws_spot_instance_request" "this" {
448448
}
449449

450450
dynamic "root_block_device" {
451-
for_each = var.root_block_device
451+
for_each = length(var.root_block_device) > 0 ? [var.root_block_device] : []
452452

453453
content {
454454
delete_on_termination = try(root_block_device.value.delete_on_termination, null)

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ variable "private_ip" {
196196

197197
variable "root_block_device" {
198198
description = "Customize details about the root block device of the instance. See Block Devices below for details"
199-
type = list(any)
200-
default = []
199+
type = any
200+
default = {}
201201
}
202202

203203
variable "secondary_private_ips" {

wrappers/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module "wrapper" {
5454
private_dns_name_options = try(each.value.private_dns_name_options, var.defaults.private_dns_name_options, {})
5555
private_ip = try(each.value.private_ip, var.defaults.private_ip, null)
5656
putin_khuylo = try(each.value.putin_khuylo, var.defaults.putin_khuylo, true)
57-
root_block_device = try(each.value.root_block_device, var.defaults.root_block_device, [])
57+
root_block_device = try(each.value.root_block_device, var.defaults.root_block_device, {})
5858
secondary_private_ips = try(each.value.secondary_private_ips, var.defaults.secondary_private_ips, null)
5959
source_dest_check = try(each.value.source_dest_check, var.defaults.source_dest_check, null)
6060
spot_block_duration_minutes = try(each.value.spot_block_duration_minutes, var.defaults.spot_block_duration_minutes, null)

0 commit comments

Comments
 (0)