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

Tags for AWS resources created implicitly by other resources #9061

Closed
ewbankkit opened this issue Jun 19, 2019 · 20 comments · Fixed by #13783
Closed

Tags for AWS resources created implicitly by other resources #9061

ewbankkit opened this issue Jun 19, 2019 · 20 comments · Fixed by #13783
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@ewbankkit
Copy link
Contributor

ewbankkit commented Jun 19, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

When AWS EC2/VPC (and maybe other service) resources are shared with another account via RAM the tags from the creating account are not copied to the accepting account and so for example a shared subnet has no Name in the accepting account's AWS Console.

We decouple much of our Terraform code by creating for example all subnet resources in one module (with a predefined set of tags) and then using a data source in another module (specifying those predefined tags) to find a specific subnet ID (for an ASG or whatever).
This won't work when a subnet is shared into an account as those predefined tags are missing.

Doing a terraform import for those shared resources won't really work as the accepting account doesn't own the resource's lifecycle and can only change tags on the resource.

My thinking is to have a Terraform resource in the accepting account that can manage just the tags on these shared VPC resources.

New or Affected Resource(s)

  • aws_subnet
  • Others TBD

References

#8457 seems to be a solution to a similar problem.

Related:

@ewbankkit ewbankkit added the enhancement Requests to existing resources that expand the functionality or scope. label Jun 19, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Jun 19, 2019
@ewbankkit ewbankkit changed the title Tags for shared EC2/VPC resources Tags for shared EC2/VPC resources in accepting/participant account Jun 19, 2019
@ewbankkit
Copy link
Contributor Author

Look also at shared Route 53 Resolver Forwarding Rules which can have tags.

@ewbankkit
Copy link
Contributor Author

Another use case is for tagging EC2 resources implicitly created by other resources such as the transit gateway attachment created by associating a Direct Connect gateway.

@aeschright aeschright added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jul 5, 2019
@ewbankkit
Copy link
Contributor Author

Another similar thing for Route 53 Hosted Zones created via Servicediscovery: #7840

@erikkn
Copy link
Contributor

erikkn commented Jul 12, 2019

This feature is very much appreciated! Looks like it is not supported by AWS yet though, so we should probably wait for them. Really annoying that the tags that you set on an object - for example the TGW - are not automatically shared; this prevents you pretty much from doing more robust setups.

@joestump
Copy link
Contributor

@erikkn AWS does allow you to tag resource by ID. My PR #8457 allows for decoupling of resource creation from tagging.

@ewbankkit
Copy link
Contributor Author

Another use case is for the EC2 resources created as part of an EKS Managed Node Group - #10915.
The tags set on the aws_eks_node_group resource are not applied to the managed EC2 resources.

@ewbankkit
Copy link
Contributor Author

ewbankkit commented Nov 23, 2019

Another use case is for the EC2 instance that satisfies an aws_spot_instance_request - See #32, #3481, #13229.

@ewbankkit
Copy link
Contributor Author

Another one - tagging DynamoDB resources: #6859.

@ewbankkit ewbankkit changed the title Tags for shared EC2/VPC resources in accepting/participant account Tags for AWS resources created implicitly by other resources Dec 1, 2019
@ewbankkit
Copy link
Contributor Author

Another one - tagging ECS cluster created for Batch: #11951.

@n3ph
Copy link
Contributor

n3ph commented Feb 22, 2020

Another one - Tagging EC2 Transit Gateway Route Tables created in cross account. They will be unnamed in the account holding the Transit Gateway itself..

@david-wells-1
Copy link
Contributor

david-wells-1 commented Mar 26, 2020

Another use case - when resource aws_vpn_connection creates connection - the attachment on the transit gateway is not/cannot be tagged.

Details here: #12535

@ewbankkit
Copy link
Contributor Author

And another bunch, the COIP and Local Gateway resources created when setting up an AWS Outpost - #12302.

@ewbankkit
Copy link
Contributor Author

@sc250024
Copy link

sc250024 commented Jun 3, 2020

Would be lovely to have a generic pass_tags or created_resource_tags for this use case. We currently don't have tags on the EC2 instances created from EKS managed node group Autoscaling groups (#9061 (comment)), so that would be nice to have. Thanks for the issue @ewbankkit !

@ewbankkit
Copy link
Contributor Author

@bflad
Copy link
Contributor

bflad commented Jun 13, 2020

A new aws_ec2_tag resource for managing individual EC2 resource tags has been merged and will release with version 2.67.0 of the Terraform AWS Provider, later next week. This resource should only be used in cases where EC2 resources are created outside Terraform (e.g. AMIs), being shared via Resource Access Manager (RAM), or implicitly created by other means (e.g. Transit Gateway VPN Attachments).

# Example configuration in Terraform 0.12 and later syntax
resource "aws_ec2_transit_gateway" "example" {}

resource "aws_customer_gateway" "example" {
  bgp_asn    = 65000
  ip_address = "172.0.0.1"
  type       = "ipsec.1"
}

resource "aws_vpn_connection" "example" {
  customer_gateway_id = aws_customer_gateway.example.id
  transit_gateway_id  = aws_ec2_transit_gateway.example.id
  type                = aws_customer_gateway.example.type
}

resource "aws_ec2_tag" "example" {
  resource_id = aws_vpn_connection.example.transit_gateway_attachment_id
  key         = "Name"
  value       = "Hello World"
}

As with any Terraform 0.12.6 or later configuration, this resource can be combined with for_each support to manage multiple resource tags, if necessary.

Thanks to @joestump and others who made the implementation possible. 👍


While the above covers EC2 resources, we would highly suggest creating individual GitHub feature requests for other AWS services since these types of general issues lack a definition of done.

Here's what I see above so far:

I will however keep this open for a short while longer since we will likely want to implement a few general enhancements to make creating these service tag resources easier, which will be the definition of done for this particular issue:

  • Implementing a "get tag" function generator within the internal/keyvaluetags package to make the resource implementations consistent
  • Switching the aws_ec2_tag resource to the above implementation
  • Documenting the process for creating these resources
  • (Optionally) Creating a generator for the tagging resources or resource functions

@bflad bflad removed the needs-triage Waiting for first response or review from a maintainer. label Jun 13, 2020
bflad added a commit that referenced this issue Jun 13, 2020
…list/get, use in aws_ec2_tag implementation

Reference: #9061

The GetTag generator simplifies the creation of the new individual service tag resources into a consistent implementation. This consistent implementation can be used to automatically generate the service tag resources themselves in the future.

Output from acceptance testing:

```
--- PASS: TestAccAWSEc2Tag_basic (485.52s)
--- PASS: TestAccAWSEc2Tag_disappears (529.67s)
--- PASS: TestAccAWSEc2Tag_Value (588.49s)
```
bflad added a commit that referenced this issue Jun 16, 2020
…list/get, use in aws_ec2_tag implementation (#13745)

* internal/keyvaluetags: Create {SERVICE}GetTag generator, support EC2 list/get, use in aws_ec2_tag implementation

Reference: #9061

The GetTag generator simplifies the creation of the new individual service tag resources into a consistent implementation. This consistent implementation can be used to automatically generate the service tag resources themselves in the future.

Output from acceptance testing:

```
--- PASS: TestAccAWSEc2Tag_basic (485.52s)
--- PASS: TestAccAWSEc2Tag_disappears (529.67s)
--- PASS: TestAccAWSEc2Tag_Value (588.49s)
```

* tests/resource/aws_ec2_tag: Add missing error check
bflad added a commit that referenced this issue Jun 17, 2020
… switch aws_ec2_tag implementation

Reference: #9061

Output from acceptance testing:

```
--- PASS: TestAccAWSEc2Tag_disappears (429.66s)
--- PASS: TestAccAWSEc2Tag_Value (530.85s)
--- PASS: TestAccAWSEc2Tag_basic (537.38s)
```
bflad added a commit that referenced this issue Mar 24, 2021
… switch aws_ec2_tag implementation

Reference: #9061

Output from acceptance testing:

```
--- PASS: TestAccAWSEc2Tag_disappears (429.66s)
--- PASS: TestAccAWSEc2Tag_Value (530.85s)
--- PASS: TestAccAWSEc2Tag_basic (537.38s)
```
ewbankkit pushed a commit that referenced this issue Aug 20, 2021
… switch aws_ec2_tag implementation

Reference: #9061

Output from acceptance testing:

```
--- PASS: TestAccAWSEc2Tag_disappears (429.66s)
--- PASS: TestAccAWSEc2Tag_Value (530.85s)
--- PASS: TestAccAWSEc2Tag_basic (537.38s)
```
@github-actions github-actions bot added this to the v3.56.0 milestone Aug 20, 2021
@github-actions
Copy link

This functionality has been released in v3.56.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@Benvorth
Copy link

Same for aws_ec2_transit_gateway_vpc_attachment, please re-open

@Benvorth
Copy link

Tested version was
required_providers { aws = { source = "hashicorp/aws" version = ">=3.56.0" } }

@github-actions
Copy link

github-actions bot commented Jun 6, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
9 participants