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

Introduce the aws_ec2_tag resource for managing individual tags on EC2 resources #8457

Merged
merged 35 commits into from
Jun 13, 2020

Conversation

joestump
Copy link
Contributor

@joestump joestump commented Apr 26, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Adds support for tagging EC2 resources that may or may not be directly managed by Terraform. My team's primary use case is attaching tags to subnets/VPCs that are managed by other teams for EKS. See the docs on VPC and subnet tagging in EKS for more details.

NOTE: This also modifies how aws_subnet and aws_vpc manage the tags attribute. Basically, if tags isn't set or hasn't changed, then it's a noop. Otherwise, we end up with tags getting blown away by these resources even when they don't define a tags attribute.

Example

resource "aws_vpc" "example" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_ec2_tag" "example" {
  resource_id = "${aws_vpc.example.id}"
  key         = "Name"
  value       = "Hello World"
}

Tests

joestump-ltm:terraform-provider-aws joe.stump$ AWS_DEFAULT_REGION='us-west-1' make testacc TESTARGS='-run=TestAccAWSEc2ResourceTag*'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSEc2ResourceTag* -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSEc2ResourceTag_basic
=== PAUSE TestAccAWSEc2ResourceTag_basic
=== RUN   TestAccAWSEc2ResourceTag_subnet
=== PAUSE TestAccAWSEc2ResourceTag_subnet
=== CONT  TestAccAWSEc2ResourceTag_basic
=== CONT  TestAccAWSEc2ResourceTag_subnet
--- PASS: TestAccAWSEc2ResourceTag_basic (23.50s)
--- PASS: TestAccAWSEc2ResourceTag_subnet (24.93s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	25.184s

@ghost ghost added size/M Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/ec2 Issues and PRs that pertain to the ec2 service. labels Apr 26, 2019
@ghost ghost added size/L Managed by automation to categorize the size of a PR. and removed size/M Managed by automation to categorize the size of a PR. labels Apr 26, 2019
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. and removed size/L Managed by automation to categorize the size of a PR. labels Apr 26, 2019
@joestump
Copy link
Contributor Author

joestump commented Jul 9, 2019

Merged in the latest from master and updated the resource to use a Retry as we were running into eventually consistent shenanigans.

Joe Stump and others added 3 commits July 9, 2019 19:25
fixing retry logic - DescribeTags returns no err and an empty list of…
@aeschright aeschright added the new-resource Introduces a new resource. label Aug 19, 2019
@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. and removed size/XL Managed by automation to categorize the size of a PR. labels Sep 12, 2019
@joestump
Copy link
Contributor Author

Recent updates:

  • Fixed conflict with master.
  • Added support for timeout when tag is being created.
  • Bumped the default timeout to 10 minutes.

@bflad bflad self-assigned this May 14, 2020
@bflad bflad added waiting-response Maintainers are waiting on response from community or contributor. and removed service/glue Issues and PRs that pertain to the glue service. labels May 14, 2020
@bflad
Copy link
Contributor

bflad commented May 15, 2020

FYI, relating to your original problem with tags, you may find the recently released provider-level ignore_tags functionality helpful. Kubernetes tagging issues was an example use case. 😄 In that context though, any of these individual service tag resources will bypass that provider-level configuration to be able to properly manage provider-level ignored tags.

Joe Stump and others added 4 commits May 19, 2020 13:38
@joestump
Copy link
Contributor Author

@bflad it's a great new config option for sure. We still have a need to be able to tag things separately like this and have been running this patch in production for a while now. I'm working with my team to get this PR cleaned up for merge. 👍

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label May 26, 2020
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label May 26, 2020
@iambrianfallon
Copy link
Contributor

@bflad I believe the changes I pushed up this morning should cover all of the changes you requested in your comment. the provider level ignore_tags feature appears to work for our use cases so I will keep an eye in here if there are any other changes you want us to make.

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 8, 2020
@bflad bflad self-requested a review June 12, 2020 23:14
@bflad bflad added this to the v2.67.0 milestone Jun 13, 2020
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much 🚀 Going to pull this in with a few minor enhancements such as import and in-place value update support.

bflad added a commit that referenced this pull request Jun 13, 2020
Reference: #8457

Changes:

* Use keyvaluetags package where possible
* Support import and in-place update of value
* Add yellow callout boxes in documentation to disuade usage with parent resources and note lack of ignore_tags usage
* Update examples and testing for real-world implementation of EC2 Transit Gateway VPN Attachment tagging

Output from acceptance testing:

```
--- PASS: TestAccAWSEc2Tag_Value (489.14s)
--- PASS: TestAccAWSEc2Tag_disappears (534.08s)
--- PASS: TestAccAWSEc2Tag_basic (538.95s)
```
@bflad bflad merged commit 9a5337a into hashicorp:master Jun 13, 2020
bflad added a commit that referenced this pull request Jun 13, 2020
@erikkn
Copy link
Contributor

erikkn commented Jun 15, 2020

@joestump, thanks a bunch for taking your time and getting this in! Really great work 💪

@ghost
Copy link

ghost commented Jun 19, 2020

This has been released in version 2.67.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 for triage. Thanks!

@ghost
Copy link

ghost commented Jul 13, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_vpn_connection tagging Support EC2 Create Tags Resource Add ec2_tag resource
8 participants