Skip to content

Add volume tags naming and output #82

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ data "aws_ami" "ubuntu-xenial" {
| security\_groups | List of associated security groups of instances |
| subnet\_id | List of IDs of VPC subnets of instances |
| tags | List of tags of instances |
| volume\_tags | List of tags of volumes of instances |
| vpc\_security\_group\_ids | List of associated security groups of instances, if running in non-default VPC |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ resource "aws_instance" "this" {
ipv6_addresses = "${var.ipv6_addresses}"

ebs_optimized = "${var.ebs_optimized}"
volume_tags = "${var.volume_tags}"
root_block_device = "${var.root_block_device}"
ebs_block_device = "${var.ebs_block_device}"
ephemeral_block_device = "${var.ephemeral_block_device}"
Expand All @@ -34,7 +33,8 @@ resource "aws_instance" "this" {
placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}"

tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
volume_tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.volume_tags)}"

lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
Expand Down Expand Up @@ -62,7 +62,6 @@ resource "aws_instance" "this_t2" {
ipv6_addresses = "${var.ipv6_addresses}"

ebs_optimized = "${var.ebs_optimized}"
volume_tags = "${var.volume_tags}"
root_block_device = "${var.root_block_device}"
ebs_block_device = "${var.ebs_block_device}"
ephemeral_block_device = "${var.ephemeral_block_device}"
Expand All @@ -77,7 +76,8 @@ resource "aws_instance" "this_t2" {
cpu_credits = "${var.cpu_credits}"
}

tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.tags)}"
volume_tags = "${merge(map("Name", (var.instance_count > 1) || (var.use_num_suffix == "true") ? format("%s-%d", var.name, count.index+1) : var.name), var.volume_tags)}"

lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
Expand Down
6 changes: 6 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ locals {
this_subnet_id = "${compact(concat(coalescelist(aws_instance.this.*.subnet_id, aws_instance.this_t2.*.subnet_id), list("")))}"
this_credit_specification = "${aws_instance.this_t2.*.credit_specification}"
this_tags = "${coalescelist(flatten(aws_instance.this.*.tags), flatten(aws_instance.this_t2.*.tags))}"
this_volume_tags = "${coalescelist(flatten(aws_instance.this.*.volume_tags), flatten(aws_instance.this_t2.*.volume_tags))}"
}

output "id" {
Expand Down Expand Up @@ -84,3 +85,8 @@ output "tags" {
description = "List of tags of instances"
value = ["${local.this_tags}"]
}

output "volume_tags" {
description = "List of tags of volumes of instances"
value = ["${local.this_volume_tags}"]
}