Skip to content

Commit

Permalink
Move volume_tags into dynamic blocks
Browse files Browse the repository at this point in the history
This effectively removes the churn-ing that is happening when an
ebs_volume is attached separately from the module

Takes advantage of the new feature in the aws provider available as of 3.24.0.
hashicorp/terraform-provider-aws#15474
  • Loading branch information
dekimsey committed Jan 15, 2021
1 parent 41d41ea commit cf9e429
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ resource "aws_instance" "this" {
kms_key_id = lookup(root_block_device.value, "kms_key_id", null)
volume_size = lookup(root_block_device.value, "volume_size", null)
volume_type = lookup(root_block_device.value, "volume_type", null)
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,
)
}
}

Expand All @@ -49,6 +55,12 @@ resource "aws_instance" "this" {
snapshot_id = lookup(ebs_block_device.value, "snapshot_id", null)
volume_size = lookup(ebs_block_device.value, "volume_size", null)
volume_type = lookup(ebs_block_device.value, "volume_type", null)
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,
)
}
}

Expand Down Expand Up @@ -92,13 +104,6 @@ resource "aws_instance" "this" {
var.tags,
)

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,
)

credit_specification {
cpu_credits = local.is_t_instance_type ? var.cpu_credits : null
}
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ terraform {
required_version = ">= 0.12.6"

required_providers {
aws = ">= 2.65"
aws = ">= 3.24.0"
}
}

0 comments on commit cf9e429

Please sign in to comment.