diff --git a/README.md b/README.md index 8f22cb7d..f06f8a30 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ No modules. | [private\_dns\_name\_options](#input\_private\_dns\_name\_options) | Customize the private DNS name options of the instance | `map(string)` | `{}` | no | | [private\_ip](#input\_private\_ip) | Private IP address to associate with the instance in a VPC | `string` | `null` | no | | [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 | -| [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 | +| [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 | | [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 | | [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 | | [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 | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index f14dfd9a..e6ca6dde 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -59,17 +59,15 @@ module "ec2_complete" { threads_per_core = 1 } enable_volume_tags = false - root_block_device = [ - { - encrypted = true - volume_type = "gp3" - throughput = 200 - volume_size = 50 - tags = { - Name = "my-root-block" - } - }, - ] + root_block_device = { + encrypted = true + volume_type = "gp3" + throughput = 200 + volume_size = 50 + tags = { + Name = "my-root-block" + } + } ebs_block_device = [ { @@ -190,29 +188,25 @@ locals { instance_type = "t3.micro" availability_zone = element(module.vpc.azs, 0) subnet_id = element(module.vpc.private_subnets, 0) - root_block_device = [ - { - encrypted = true - volume_type = "gp3" - throughput = 200 - volume_size = 50 - tags = { - Name = "my-root-block" - } + root_block_device = { + encrypted = true + volume_type = "gp3" + throughput = 200 + volume_size = 50 + tags = { + Name = "my-root-block" } - ] + } } two = { instance_type = "t3.small" availability_zone = element(module.vpc.azs, 1) subnet_id = element(module.vpc.private_subnets, 1) - root_block_device = [ - { - encrypted = true - volume_type = "gp2" - volume_size = 50 - } - ] + root_block_device = { + encrypted = true + volume_type = "gp2" + volume_size = 50 + } } three = { instance_type = "t3.medium" @@ -270,17 +264,15 @@ module "ec2_spot_instance" { } enable_volume_tags = false - root_block_device = [ - { - encrypted = true - volume_type = "gp3" - throughput = 200 - volume_size = 50 - tags = { - Name = "my-root-block" - } - }, - ] + root_block_device = { + encrypted = true + volume_type = "gp3" + throughput = 200 + volume_size = 50 + tags = { + Name = "my-root-block" + } + } ebs_block_device = [ { @@ -389,17 +381,15 @@ module "ec2_cpu_options" { amd_sev_snp = "enabled" } enable_volume_tags = false - root_block_device = [ - { - encrypted = true - volume_type = "gp3" - throughput = 200 - volume_size = 50 - tags = { - Name = "my-root-block" - } - }, - ] + root_block_device = { + encrypted = true + volume_type = "gp3" + throughput = 200 + volume_size = 50 + tags = { + Name = "my-root-block" + } + } ebs_block_device = [ { diff --git a/main.tf b/main.tf index 2f291307..f005057a 100644 --- a/main.tf +++ b/main.tf @@ -76,7 +76,7 @@ resource "aws_instance" "this" { } dynamic "root_block_device" { - for_each = var.root_block_device + for_each = length(var.root_block_device) > 0 ? [var.root_block_device] : [] content { delete_on_termination = try(root_block_device.value.delete_on_termination, null) @@ -254,7 +254,7 @@ resource "aws_instance" "ignore_ami" { } dynamic "root_block_device" { - for_each = var.root_block_device + for_each = length(var.root_block_device) > 0 ? [var.root_block_device] : [] content { delete_on_termination = try(root_block_device.value.delete_on_termination, null) @@ -448,7 +448,7 @@ resource "aws_spot_instance_request" "this" { } dynamic "root_block_device" { - for_each = var.root_block_device + for_each = length(var.root_block_device) > 0 ? [var.root_block_device] : [] content { delete_on_termination = try(root_block_device.value.delete_on_termination, null) diff --git a/variables.tf b/variables.tf index d5b8bc0e..fe25d7cf 100644 --- a/variables.tf +++ b/variables.tf @@ -196,8 +196,8 @@ variable "private_ip" { variable "root_block_device" { description = "Customize details about the root block device of the instance. See Block Devices below for details" - type = list(any) - default = [] + type = any + default = {} } variable "secondary_private_ips" { diff --git a/wrappers/main.tf b/wrappers/main.tf index 494d2cbc..4e7fb509 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -54,7 +54,7 @@ module "wrapper" { private_dns_name_options = try(each.value.private_dns_name_options, var.defaults.private_dns_name_options, {}) private_ip = try(each.value.private_ip, var.defaults.private_ip, null) putin_khuylo = try(each.value.putin_khuylo, var.defaults.putin_khuylo, true) - root_block_device = try(each.value.root_block_device, var.defaults.root_block_device, []) + root_block_device = try(each.value.root_block_device, var.defaults.root_block_device, {}) secondary_private_ips = try(each.value.secondary_private_ips, var.defaults.secondary_private_ips, null) source_dest_check = try(each.value.source_dest_check, var.defaults.source_dest_check, null) spot_block_duration_minutes = try(each.value.spot_block_duration_minutes, var.defaults.spot_block_duration_minutes, null)