Setup launch template with tag_secifications with multiple resources

Viewed 1048
1 Answers

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"
    }
  }

}
Related