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

[AWS] Pass tags to module creating an ASG #9098

Closed
mcinteer opened this issue Sep 28, 2016 · 13 comments
Closed

[AWS] Pass tags to module creating an ASG #9098

mcinteer opened this issue Sep 28, 2016 · 13 comments

Comments

@mcinteer
Copy link
Contributor

Hi there,

Terraform Version

$ terraform -v
Terraform v0.7.4

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_autoscaling_group

Terraform Configuration Files

This is an ASG defined in a module with some default tags:

resource "aws_autoscaling_group" "asg" {
  name = "${var.env}-${var.cell}-${var.app}"
  launch_configuration = "${aws_launch_configuration.lc.name}"
  .
  .
  .
  tag {
    key = "Name"
    value = "${var.env}-${var.app}"
    propagate_at_launch = true
  }

  tag {
    key = "app"
    value = "${var.env}-${var.app}"
    propagate_at_launch = true
  }
.
.
.

Info

I'd like to be able to pass this module some extra tags to add to the ASG. for example if I have a couple of different stacks using this module and they both require these default tags but then one of them requires some additional tags. Is this available already? I've done a fair amount of googling on this but cannot find anything on it.

It seems that because each tag is added individually rather than a list of tags that I can't add to the list. Is there a workaround for this or can we get it implemented?

Thanks,
Ryan

@mcinteer
Copy link
Contributor Author

Been thinking a little more about this this evening and looking at the way the autoscaling group is implemented in TF I think that it would be very difficult to add in extensible tags like I want. Would a potential solution be to create a new resource type call something like aws_autoscaling_tag which could take in the name of the scaling group, the key and value of the tag. Then apply the tag to the existing group?

@mcinteer
Copy link
Contributor Author

I have been playing around with the overrides feature built in to terraform to try and achieve this. But it would appear that I cannot override a resource in a module from the root, is this correct?

@morkot
Copy link

morkot commented Dec 1, 2016

+1
I think this should be implemented and standardized as in aws_instance resource.

@morkot
Copy link

morkot commented Dec 1, 2016

So, let's compare ASG and single EC2 instance tag description in terraform:

ASG:

resource "aws_autoscaling_group" "bar" {
...
  tag {
    key = "foo"
    value = "bar"
    propagate_at_launch = true
  }
  tag {
    key = "lorem"
    value = "ipsum"
    propagate_at_launch = false
  }
}

EC2 Instance:

resource "aws_instance" "bar" {
...
    tags = {
        Name = "HelloWorld"
        foo     = "bar"
    }

It would be great to have standard description of tags, smth like

ASG:

resource "aws_autoscaling_group" "bar" {
...
    tags = {
      Name = {
        value = "my-name"
        propagate_at_launch = true
      },
      MySecondTag = {
        value = "tag2"
        propagate_at_launch = false
      }
    }
}

In this way tags for ASG can be described in variables.tf and overridden later when module reused.

@morkot
Copy link

morkot commented Dec 1, 2016

Or even simpler:
split those two tags to two different arguments, like:

resource "aws_autoscaling_group" "bar" {
...
    tags_propagated = {
      Name = "my-name"
      AnotherTagForInstances = "foo"
    }

    tags = {
      MyTagForASGNotPropagted = "baz"
    }
}

@morkot
Copy link

morkot commented Dec 1, 2016

@mitchellh , could you take a look on this (above)

@jordiclariana
Copy link

jordiclariana commented Jan 30, 2017

It would be awesome to have this. Is there any plans to implement it?

@dene14
Copy link

dene14 commented Mar 26, 2017

Seriously... is it going to be implemented? Lack of this functionality affects flexibility in writing modules in a hard way

@CarlInglisBJSS
Copy link

Is there any news on this? Being able to set tags in the same way as other resources would be a great help for us.

@pgroudas
Copy link

I think this will issue will resolve it, which is slated for the next release: #13574

@ashb
Copy link
Contributor

ashb commented May 23, 2017

That issue is good, but I can't think of any way with interpolations to let a module accept a map of tags (to set on VPC/segurity groups say) and to also apply those to ASG-created instances.

i.e. Is it possible to go from {"x": "y", "z": "w"} to [{"Key": "x", "Value": "y", "PropagateAtLaunch": true},{"Key": "z", "Value": "w", "PropagateAtLaunch": true}] using just pure HCL/interpolations?

@carlosonunez
Copy link

I had to write a script to get around this. Feel free to use it here: https://github.com/carlosonunez/terraform_asg_tag_creator

@ghost
Copy link

ghost commented Apr 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants