From 8258fb16e5dfc2049bebafcf616f2ae64a4fe04a Mon Sep 17 00:00:00 2001 From: Shayne Clausson Date: Sat, 7 Oct 2017 23:02:15 +0200 Subject: [PATCH] Use interpolated tags syntax to add extra tags to cluster nodes --- modules/vault-cluster/README.md | 17 +++++++++++++++++ modules/vault-cluster/main.tf | 11 ++++++----- modules/vault-cluster/variables.tf | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/modules/vault-cluster/README.md b/modules/vault-cluster/README.md index a883c919..6a58405f 100644 --- a/modules/vault-cluster/README.md +++ b/modules/vault-cluster/README.md @@ -29,6 +29,23 @@ module "vault_cluster" { #!/bin/bash /opt/vault/bin/run-vault --s3-bucket ${var.vault_s3_bucket} --s3-bucket-region ${var.aws_region} --tls-cert-file /opt/vault/tls/vault.crt.pem --tls-key-file /opt/vault/tls/vault.key.pem EOF + + # Add tag to each node in the cluster with value set to var.cluster_name + cluster_tag_key = "Name" + + # Optionally add extra tags to each node in the cluster + cluster_extra_tags = [ + { + key = "Environment" + value = "Dev" + propagate_at_launch = true + }, + { + key = "Department" + value = "Ops" + propagate_at_launch = true + } + ] # ... See vars.tf for the other parameters you must define for the vault-cluster module } diff --git a/modules/vault-cluster/main.tf b/modules/vault-cluster/main.tf index 7a356294..9ba80811 100644 --- a/modules/vault-cluster/main.tf +++ b/modules/vault-cluster/main.tf @@ -28,11 +28,12 @@ resource "aws_autoscaling_group" "autoscaling_group" { health_check_grace_period = "${var.health_check_grace_period}" wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}" - tag { - key = "${var.cluster_tag_key}" - value = "${var.cluster_name}" - propagate_at_launch = true - } + tags = ["${concat( + list( + map("key", var.cluster_tag_key, "value", var.cluster_name, "propagate_at_launch", true) + ), + var.cluster_extra_tags) + }"] } # --------------------------------------------------------------------------------------------------------------------- diff --git a/modules/vault-cluster/variables.tf b/modules/vault-cluster/variables.tf index 1df6d93f..8fa43c83 100644 --- a/modules/vault-cluster/variables.tf +++ b/modules/vault-cluster/variables.tf @@ -80,6 +80,20 @@ variable "cluster_tag_key" { default = "Name" } +variable "cluster_extra_tags" { + description = "A list of additional tags to add to each Instance in the ASG. Each element in the list must be a map with the keys key, value, and propagate_at_launch" + type = "list" + #example: + # default = [ + # { + # key = "Environment" + # value = "Dev" + # propagate_at_launch = true + # } + # ] + default = [] +} + variable "termination_policies" { description = "A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are OldestInstance, NewestInstance, OldestLaunchConfiguration, ClosestToNextInstanceHour, Default." default = "Default"