Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup tag_specifications for launch template resource #17609

Open
tkumark opened this issue Feb 14, 2021 · 4 comments
Open

How to setup tag_specifications for launch template resource #17609

tkumark opened this issue Feb 14, 2021 · 4 comments
Labels
documentation Introduces or discusses updates to documentation.

Comments

@tkumark
Copy link

tkumark commented Feb 14, 2021

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

image

@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 14, 2021
@DrFaust92 DrFaust92 added documentation Introduces or discusses updates to documentation. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. and removed needs-triage Waiting for first response or review from a maintainer. documentation Introduces or discusses updates to documentation. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. labels Feb 14, 2021
@DrFaust92
Copy link
Collaborator

A documentation example can be added but for this specific issue:

  tag_specifications {
    resource_type = "instance"

    tags = {
      Name = "test"
    }
  }

  tag_specifications {
    resource_type = "volume"

    tags = {
      Name = "test"
    }
  }

can achieve this. to make this more DRY you can use https://www.terraform.io/docs/language/expressions/dynamic-blocks.html

@ChaitanyaChandra
Copy link

  • use the below example.
locals {
  tags_dest = ["instance", "volume", "elastic-gpu", "network-interface", "spot-instances-request"]
}

  dynamic "tag_specifications" {
    for_each = toset(local.tags_dest)
    content {
      resource_type = tag_specifications.key
      tags = {
          ENV = "dev"
           }
       }
    }

@mafeko
Copy link

mafeko commented Sep 8, 2022

Be aware that aws will not be able to start a new instance (in the Autoscaling Group) if you specify a resource_type which you don't launch.

Launching a new EC2 instance. Status Reason: You cannot specify tags for elastic GPUs if there are no elastic GPUs being created by the request. Launching EC2 instance failed.

@yaroslav-nakonechnikov
Copy link

@mafeko this is strange.

if default tags are set on provider level, i expect that all resources will be tagged.... but i see why it don't happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Introduces or discusses updates to documentation.
Projects
None yet
Development

No branches or pull requests

5 participants