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

feat: Support default_tags in aws_autoscaling_group and launch_template #1968

Closed
wants to merge 3 commits into from

Conversation

raizyr
Copy link
Contributor

@raizyr raizyr commented Mar 25, 2022

Description

  • Add new attribute launch_template_use_default_tags to EKS managed node group and self managed node group module definitions. When set to true, the default tags configured on the provider will be added to the launch_template tag_specifications.
  • Add new attribute asg_use_default_tags to EKS self managed node group module definition. When set to true, the default tags configured on the provider will be added to the autoscaling_group tags.
  • Update the root module to look at both var.eks_managed_node_groups or var.eks_managed_node_group_defaults and var.self_managed_node_groups or var.self_managed_node_group_defaults and pass the result to the apprioriate node group module.

Motivation and Context

Fixes #1916

Breaking Changes

No

How Has This Been Tested?

  • [✅ ] I have tested and validated these changes using one or more of the provided examples/* projects

@@ -238,7 +242,7 @@ resource "aws_launch_template" "this" {
for_each = toset(["instance", "volume", "network-interface"])
content {
resource_type = tag_specifications.key
tags = merge(var.tags, { Name = var.name }, var.launch_template_tags)
tags = merge(local.launch_template_default_tags, { Name = var.name }, var.launch_template_tags)
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to set this here? from my understanding, only autoscaling groups behave differently when it comes to default tags

Copy link
Contributor Author

@raizyr raizyr Mar 28, 2022

Choose a reason for hiding this comment

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

I double checked what I'd been seeing on Friday, and while the provider default tags do get automatically included in the launch_template resource's tags, they do not get included in the tag_specifications of the launch_template. Those instead act much like the ASG tag specifications. Adding the ability to include the default tags to the launch_template tag specifications ensures that any instances created from the launch_template will also have the default tags set on the instance itself.

Edit to fix the misleading resource tags comment. The launch_template resource has both a tags and tag_specifications input attribute. The default_tags do get added to the tags_all attribute of the state, however they do not get added to the tag_specifications that propagate down to the instance, network-interface, and volume.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would a different variable name make sense to make it clearer? Maybe tag_specification_use_default_tags or something similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found a relevant issue in the provider repo. hashicorp/terraform-provider-aws#19387

Copy link
Member

Choose a reason for hiding this comment

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

I think for now we leave off the launch template changes - this matches what we have in the autoscaling module (which at some point will get folded into this module) and just add to the autoscaling group

Copy link
Contributor Author

@raizyr raizyr Mar 28, 2022

Choose a reason for hiding this comment

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

I'm very confused. The module as it exists right now is not able to correctly set provider default tags for resources created by neither an autoscaling group nor a launch template. Are you saying that only the autoscaling group use case should be fixed?

Copy link
Member

Choose a reason for hiding this comment

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

  1. We cannot control the autoscaling groups created by the EKS managed node group service so there is no solution for default tags on that resource currently other than using the external autoscaling group tags resource (has to be external to the module Add Tags to ASG when using node groups #1558 (comment))
  2. We should mirror what we did in the autoscaling group module for the self-managed node group module https://github.com/terraform-aws-modules/terraform-aws-autoscaling/blob/3c928b8cfb2be46ff756be350fb26c33ee1a640a/main.tf#L10-L15 which is the same as what the Terraform docs specify. We only add the default tags to the autoscaling group resource

Copy link
Member

Choose a reason for hiding this comment

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

I understand there are many issues related to default tags right now which is why I am cautious regarding what gets introduced. The Terraform docs only offer the caveat for autoscaling groups https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider and not launch templates and this is what we have mimicked in the autoscaling group module without issue. So for now, I think that is a safe path if we want to introduce that change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, unfortunately I need to maintain my company fork with the launch template changes, since that is the issue I needed to solve when I stumbled across the open issue about the asg. I'll try to get a moment to pull just the asg changes over to a fork on my personal github and submit a new PR.

@@ -229,7 +233,7 @@ resource "aws_launch_template" "this" {
for_each = toset(["instance", "volume", "network-interface"])
content {
resource_type = tag_specifications.key
tags = merge(var.tags, { Name = var.name }, var.launch_template_tags)
tags = merge(local.launch_template_default_tags, { Name = var.name }, var.launch_template_tags)
Copy link
Member

Choose a reason for hiding this comment

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

same comment as above - why set on launch template explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above

@raizyr
Copy link
Contributor Author

raizyr commented Mar 28, 2022

I'm pretty sure that the default tags do not get set automatically on the launch template, but I will double check.

@raizyr raizyr force-pushed the master branch 3 times, most recently from 7f491c2 to 79b2975 Compare March 28, 2022 15:52
@github-actions
Copy link

github-actions bot commented Nov 9, 2022

I'm going to lock this pull request 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 related to this change, 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 Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support default_tags in aws_autoscaling_group
2 participants