base on the documentation example given below I see the tag set for instance type. But If I want the same tag to be applied to multiple resources then how would I set it up https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template
tag_specifications {
resource_type = "instance"
tags = {
Name = "test"
}
}

You either specify it twice or use dynamic blocks. Example with dynamic blocks is:
variable "to_tag" {
default = ["instance", "volume"]
}
resource "aws_launch_template" "foo" {
name = "foo"
image_id = data.aws_ami.server.id
instance_type = "t2.micro"
dynamic "tag_specifications" {
for_each = toset(var.to_tag)
content {
resource_type = tag_specifications.key
tags = {
Name = "test"
}
}
}
}
or simply specify it twice:
resource "aws_launch_template" "foo" {
name = "foo"
image_id = data.aws_ami.server.id
instance_type = "t2.micro"
tag_specifications {
resource_type = "instance"
tags = {
Name = "test"
}
}
tag_specifications {
resource_type = "volume"
tags = {
Name = "test"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With