Skip to content

Commit

Permalink
feat: use a map for root_block_device instead of list
Browse files Browse the repository at this point in the history
  • Loading branch information
Yethal committed Jun 19, 2024
1 parent 4f8387d commit 976ad60
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ No modules.
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
90 changes: 40 additions & 50 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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 = [
{
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 976ad60

Please sign in to comment.