Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Use tag instead of tags in aws_autoscaling_group #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 24 additions & 15 deletions modules/consul-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ terraform {
required_version = ">= 0.12.26"
}

locals {
asg_tags = [
{
key = "Name"
value = var.cluster_name
propagate_at_launch = true
},
{
key = var.cluster_tag_key
value = var.cluster_tag_value
propagate_at_launch = true
}
]
}

# ---------------------------------------------------------------------------------------------------------------------
# CREATE AN AUTO SCALING GROUP (ASG) TO RUN CONSUL
# ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -36,21 +51,15 @@ resource "aws_autoscaling_group" "autoscaling_group" {

protect_from_scale_in = var.protect_from_scale_in

tags = flatten(
[
{
key = "Name"
value = var.cluster_name
propagate_at_launch = true
},
{
key = var.cluster_tag_key
value = var.cluster_tag_value
propagate_at_launch = true
},
var.tags,
]
)
dynamic "tag" {
for_each = concat(local.asg_tags, var.tags)

content {
key = lookup(tag.value, "key", null)
value = lookup(tag.value, "value", null)
propagate_at_launch = lookup(tag.value, "propagate_at_launch", null)
}
}

dynamic "initial_lifecycle_hook" {
for_each = var.lifecycle_hooks
Expand Down