From b81a5025dd4d26f8b5f2a870ab6c5ce1b128308b Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Wed, 12 May 2021 10:27:56 +0200 Subject: [PATCH] fix: root_block_device tags conflicts --- README.md | 3 ++- examples/basic/main.tf | 4 ++++ main.tf | 4 ++-- variables.tf | 8 +++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index df9d3164..c565995e 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ No modules. | [disable\_api\_termination](#input\_disable\_api\_termination) | If true, enables EC2 Instance Termination Protection | `bool` | `false` | no | | [ebs\_block\_device](#input\_ebs\_block\_device) | Additional EBS block devices to attach to the instance | `list(map(string))` | `[]` | no | | [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no | +| [enable\_volume\_tags](#input\_enable\_volume\_tags) | Whether to enable volume tags (if enabled it conflicts with root\_block\_device tags) | `bool` | `true` | no | | [ephemeral\_block\_device](#input\_ephemeral\_block\_device) | Customize Ephemeral (also known as Instance Store) volumes on the instance | `list(map(string))` | `[]` | no | | [get\_password\_data](#input\_get\_password\_data) | If true, wait for password data to become available and retrieve it. | `bool` | `false` | no | | [iam\_instance\_profile](#input\_iam\_instance\_profile) | The IAM Instance Profile to launch the instance with. Specified as the name of the Instance Profile. | `string` | `""` | no | @@ -130,7 +131,7 @@ No modules. | [placement\_group](#input\_placement\_group) | The Placement Group to start the instance in | `string` | `""` | no | | [private\_ip](#input\_private\_ip) | Private IP address to associate with the instance in a VPC | `string` | `null` | no | | [private\_ips](#input\_private\_ips) | A list of private IP address to associate with the instance in a VPC. Should match the number of instances. | `list(string)` | `[]` | 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(map(string))` | `[]` | 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 | | [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` | `true` | no | | [subnet\_id](#input\_subnet\_id) | The VPC Subnet ID to launch in | `string` | `""` | no | | [subnet\_ids](#input\_subnet\_ids) | A list of VPC Subnet IDs to launch in | `list(string)` | `[]` | no | diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 9e2515d8..55af7f97 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -90,10 +90,14 @@ module "ec2" { user_data_base64 = base64encode(local.user_data) + enable_volume_tags = false root_block_device = [ { volume_type = "gp2" volume_size = 10 + tags = { + Name = "my-root-block" + } }, ] diff --git a/main.tf b/main.tf index f5017123..c67cabc8 100644 --- a/main.tf +++ b/main.tf @@ -93,12 +93,12 @@ resource "aws_instance" "this" { var.tags, ) - volume_tags = merge( + volume_tags = var.enable_volume_tags ? merge( { "Name" = var.instance_count > 1 || var.use_num_suffix ? format("%s${var.num_suffix_format}", var.name, count.index + 1) : var.name }, var.volume_tags, - ) + ) : null credit_specification { cpu_credits = local.is_t_instance_type ? var.cpu_credits : null diff --git a/variables.tf b/variables.tf index 3662f265..c4bd848d 100644 --- a/variables.tf +++ b/variables.tf @@ -145,6 +145,12 @@ variable "tags" { default = {} } +variable "enable_volume_tags" { + description = "Whether to enable volume tags (if enabled it conflicts with root_block_device tags)" + type = bool + default = true +} + variable "volume_tags" { description = "A mapping of tags to assign to the devices created by the instance at launch time" type = map(string) @@ -153,7 +159,7 @@ variable "volume_tags" { variable "root_block_device" { description = "Customize details about the root block device of the instance. See Block Devices below for details" - type = list(map(string)) + type = list(any) default = [] }