From d845a77cb4921b8b06d09fc991c73f91da84c4bd Mon Sep 17 00:00:00 2001 From: Orla Dunlop Date: Tue, 10 Sep 2024 13:22:48 +0100 Subject: [PATCH] chore(ec2): add default tags to launch template Signed-off-by: Orla Dunlop --- modules/ec2/main.tf | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/ec2/main.tf b/modules/ec2/main.tf index fa98476..fdb60ca 100644 --- a/modules/ec2/main.tf +++ b/modules/ec2/main.tf @@ -104,6 +104,8 @@ locals { name = format("%s-%s-%s", var.service, var.environment, local.role) } +data "aws_default_tags" "current" {} + module "security_groups" { count = local.create_security_groups source = "../security_groups" @@ -189,15 +191,23 @@ resource "aws_launch_template" "kong" { encrypted = true } } - + tag_specifications { resource_type = "instance" - tags = var.tags_asg + tags = merge(data.aws_default_tags.current.tags, var.tags, { + Name = local.name, + }) } tag_specifications { resource_type = "volume" - tags = var.tags_asg + tags = merge(data.aws_default_tags.current.tags, var.tags, { + Name = local.name, + }) + } + + tags = { + Name = local.name, } lifecycle {