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 - tagging of resources #1296

Closed
5 of 7 tasks
radeksimko opened this issue Mar 25, 2015 · 16 comments
Closed
5 of 7 tasks

AWS - tagging of resources #1296

radeksimko opened this issue Mar 25, 2015 · 16 comments

Comments

@radeksimko
Copy link
Member

radeksimko commented Mar 25, 2015

As requested by @catsby in #1080 (comment) I'm creating this meta-issue to track all tagging functionality for AWS in TF.

EC2-related tagging

Existing

It's worth pointing out that the existing ./builtin/providers/aws/tags.go should really be called ec2_tags.go as it in fact uses the EC2 API only and deals with tags that are related to EC2 only which are currently following:

  • aws_instance
  • aws_internet_gateway
  • aws_network_acl
  • aws_route_table
  • aws_security_group
  • aws_subnet
  • aws_vpc
  • aws_vpc_peering_connection

Missing

Here's the full list of EC2 resources that can be tagged using the same API endpoint which means that we're missing tagging functionality in the EC2 world for these:

EC2-UNrelated tags

I think most of the resources having the simple tag structure as below 🔽

type Tag struct {
    Key   aws.StringValue `ec2:"Key" xml:"key"`
    Value aws.StringValue `ec2:"Value" xml:"value"`
}

may theoretically work with the existing tagging logic as long as we can abstract the EC2-specific API calls & data-types that we currently have in ./builtin/providers/aws/tags.go.

grep -i 'ec2' ./builtin/providers/aws/tags.go
./builtin/providers/aws/tags.go:    "github.com/hashicorp/aws-sdk-go/gen/ec2"
./builtin/providers/aws/tags.go:func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
./builtin/providers/aws/tags.go:            err := conn.DeleteTags(&ec2.DeleteTagsRequest{
./builtin/providers/aws/tags.go:            err := conn.CreateTags(&ec2.CreateTagsRequest{
./builtin/providers/aws/tags.go:func diffTags(oldTags, newTags []ec2.Tag) ([]ec2.Tag, []ec2.Tag) {
./builtin/providers/aws/tags.go:    var remove []ec2.Tag
./builtin/providers/aws/tags.go:func tagsFromMap(m map[string]interface{}) []ec2.Tag {
./builtin/providers/aws/tags.go:    result := make([]ec2.Tag, 0, len(m))
./builtin/providers/aws/tags.go:        result = append(result, ec2.Tag{
./builtin/providers/aws/tags.go:func tagsToMap(ts []ec2.Tag) map[string]string {

Resources that would benefit from this as these have the same Tag structure but not part of the EC2 group:

EC2-UNrelated requiring extra care

All these will most likely require resource-specific code for handling tags

autoscaling - #1080

type Tag struct {
    Key               aws.StringValue  `query:"Key" xml:"Key"`
    PropagateAtLaunch aws.BooleanValue `query:"PropagateAtLaunch" xml:"PropagateAtLaunch"`
    ResourceID        aws.StringValue  `query:"ResourceId" xml:"ResourceId"`
    ResourceType      aws.StringValue  `query:"ResourceType" xml:"ResourceType"`
    Value             aws.StringValue  `query:"Value" xml:"Value"`
}

route53

type Tag struct {
    XMLName xml.Name

    Key   aws.StringValue `xml:"Key"`
    Value aws.StringValue `xml:"Value"`
}

s3 - #1312

type Tag struct {
    XMLName xml.Name

    Key   aws.StringValue `xml:"Key"`
    Value aws.StringValue `xml:"Value"`
}
@radeksimko
Copy link
Member Author

@catsby feel free to modify and/or reorganise things if needed.

@catsby
Copy link
Contributor

catsby commented Mar 25, 2015

Excellent, thanks @radeksimko !

@catsby
Copy link
Contributor

catsby commented Mar 25, 2015

Right now I've duplicated the tags.go for the non-EC2 resource(s) I've added, ELB and RDS.

I plan to introduce a simple Tag struct like you've shown above. The idea is to make diffTags(), tagsToMap() and tagsFromMap() work on that generic tag.

Each resource to be responsible for converting from the simple Tag to their own version (ex. rds.Tag), and maintain their own setTags func as needed.

Most of the ec2 resources should be easy and not require their own file.
The more complicated ones like ASG will need a lot more in their own tags.go file, as @radeksimko has done in #1080 with it's own diff'ing.

In the end, all this is to reuse those three funcs mentioned, as much as possible.

@wazoo
Copy link

wazoo commented Mar 26, 2015

It is great that you are tracking this, now that AWS has implemented the Resource Groups UI tags will become even more valuable going forward.

@catsby
Copy link
Contributor

catsby commented Mar 26, 2015

ASG Tagging was just merged with #1319

@arothian
Copy link

Any update on this? Eagerly awaiting tagging for EBS volumes so I can convince my boss that terraform supports all our use cases. 👍

@jtopper
Copy link
Contributor

jtopper commented May 29, 2015

👍 This is one of the things we're waiting on too.

@radeksimko
Copy link
Member Author

@arothian @jtopper #2135

@arothian
Copy link

@radeksimko Awesome thanks! Is it significantly different to provide tagging for the volumes from the block_device configuration in aws_instance? I guess I need to learn Go.

@jtopper
Copy link
Contributor

jtopper commented May 29, 2015

That's my use case too - I want to be able to tag ebs_block_device attributes in the aws_instance resource type, and my go-fu is similarly weak :)

@phinze
Copy link
Contributor

phinze commented May 29, 2015

@jtopper @arothian The ebs_block_device attribute on instances uses the AWS API's BlockDeviceMapping functionality, which I don't believe supports tagging (feel free to link the docs if you can find it though! [1]).

So if you want to tag a volume, you'll need to use this ebs_volume and the new volume_attachment resource (#2050) to attach the volume after the instance is created.

[1] I was looking here https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html

@jtopper
Copy link
Contributor

jtopper commented May 29, 2015

@phinze: Ah yes, you're quite right. I misread how we're doing that in our existing fog-based tooling, where we're actually doing something similar to what you describe here. Thanks! (and thanks @radeksimko - hit me up for a beer next time we're in the same place!)

@pdecat
Copy link
Contributor

pdecat commented Aug 30, 2016

Tags are now also supported on CloudFront distributions (since 2016/08/01 apparently):

I did not find a corresponding issue, should I create one?

@catsby
Copy link
Contributor

catsby commented Nov 3, 2016

Hey friends I'm going to close this meta-issue now. If you find a resource that is missing tag support, please open a new issue for it.

Thanks!

@catsby catsby closed this as completed Nov 3, 2016
@smicha
Copy link

smicha commented Jul 2, 2018

is it possible to update tags on a terraform managed ASG from the cli

@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

9 participants