Skip to content

Commit

Permalink
Add volume tags naming and output (#82)
Browse files Browse the repository at this point in the history
* Add tags naming policy on volume_tags

* Add volume_tags in outputs
  • Loading branch information
LeeXun authored and antonbabenko committed Jun 6, 2019
1 parent cab232d commit 70aae03
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,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}"]
}

0 comments on commit 70aae03

Please sign in to comment.