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

[Enhancement]: Allow setting ignore_tags via environment variables #35243

Closed
bberg-indeed opened this issue Jan 11, 2024 · 4 comments · Fixed by #35264
Closed

[Enhancement]: Allow setting ignore_tags via environment variables #35243

bberg-indeed opened this issue Jan 11, 2024 · 4 comments · Fixed by #35264
Labels
enhancement Requests to existing resources that expand the functionality or scope. provider Pertains to the provider itself, rather than any interaction with AWS. tags Pertains to resource tagging.
Milestone

Comments

@bberg-indeed
Copy link
Contributor

bberg-indeed commented Jan 11, 2024

Description

We would like to be able to configure the ignore_tags parameter of the AWS provider using environment variables.

We have a process that applies a tag to AWS resources, and want to prevent this tag from being overwritten every time a Terraform plan is applied. Our organization has thousands of different instances of the AWS provider across several hundred repositories, making it difficult to ensure that every instance has ignore_tags configured correctly.

If ignore_tags were configurable via an environment variable, we could set it globally via a shared Terraform Enterprise variable set, eliminating the need to modify every instance of the AWS provider.

I propose the following environment variables:

  • TF_AWS_IGNORE_TAGS_KEYS=<comma-separated list of keys>
  • TF_AWS_IGNORE_TAGS_KEY_PREFIXES=<comma-separated list of key prefixes>

HCL string tuples would be another option for the format of the variables.

There is an additional question of how to resolve explicit specification of ignore_tags with specification via environment variables. I see a few options:

  1. An explicit ignore_tags argument overrides both environment variables, regardless of whether keys, key_prefixes, or both are specified.
  2. An explicit ignore_tags argument overrides TF_AWS_IGNORE_TAGS_KEYS iff it has a keys argument, and TF_AWS_IGNORE_TAGS_KEY_PREFIXES iff it has a key_prefixes argument.
  3. Key and prefix sets specified via ignore_tags are merged with those specified via environment variables, rather than fully overriding them.

If we go with option 1 or 2, it would still be possible for module owners to explicitly merge the lists specified in TF_AWS_IGNORE_TAGS_KEYS or TF_AWS_IGNORE_TAGS_KEY_PREFIXES with an additional set of keys or prefixes via setunion(). With option 3, there would be no way for module owners to remove keys or prefixes from the ignore list, which may be regarded as a feature or limitation, depending on use case.

My preference is for option 3, merging, but I'm not sure which is more in line with Terraform's overall design philosophy. It would also be possible to specify override/merge behavior via an additional environment variable, although this would complicate things more than may be desirable.

Affected Resource(s) and/or Data Source(s)

  • All resources managed by affected AWS providers

Potential Terraform Configuration

# Assume the following environment variables:
# TF_AWS_IGNORE_TAGS_KEYS=owner,commit
# TF_AWS_IGNORE_TAGS_KEY_PREFIXES=author_,team_

# Provider definition as written:
provider "aws" {
  region = "us-east-1"
  ignore_tags {
    keys = ["env"]
  }
}

# Effective provider definition, if option 3 is implemented (my preference):
provider "aws" {
  region = "us-east-1"
  ignore_tags {
    keys = ["owner", "commit", "env"]
    key_prefixes = ["author_", "team_"]
  }
}

# Effective provider definition if option 1 is implemented:
provider "aws" {
  region = "us-east-1"
  ignore_tags {
    keys = ["env"]
  }
}

# Effective provider definition if option 2 is implemented:
provider "aws" {
  region = "us-east-1"
  ignore_tags {
    keys = ["env"]
    key_prefixes = ["author_", "team_"]
  }
}

References

Would you like to implement a fix?

Yes

@bberg-indeed bberg-indeed added the enhancement Requests to existing resources that expand the functionality or scope. label Jan 11, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jan 11, 2024
@bberg-indeed bberg-indeed changed the title [Enhancement]: [Enhancement]: Allow setting provider ignore_tags via environment variables Jan 11, 2024
@bberg-indeed bberg-indeed changed the title [Enhancement]: Allow setting provider ignore_tags via environment variables [Enhancement]: Allow setting ignore_tags via environment variables Jan 11, 2024
@justinretzolk justinretzolk added provider Pertains to the provider itself, rather than any interaction with AWS. tags Pertains to resource tagging. and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 11, 2024
Copy link

github-actions bot commented Aug 6, 2024

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.62.0 milestone Aug 6, 2024
Copy link

github-actions bot commented Aug 9, 2024

This functionality has been released in v5.62.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!

Copy link

github-actions bot commented Sep 9, 2024

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 Sep 9, 2024
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. provider Pertains to the provider itself, rather than any interaction with AWS. tags Pertains to resource tagging.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants