-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ data "aws_partition" "current" {} | |
|
||
data "aws_caller_identity" "current" {} | ||
|
||
data "aws_default_tags" "current" {} | ||
|
||
data "aws_ami" "eks_default" { | ||
count = var.create ? 1 : 0 | ||
|
||
|
@@ -42,6 +44,8 @@ module "user_data" { | |
|
||
locals { | ||
launch_template_name_int = coalesce(var.launch_template_name, "${var.name}-node-group") | ||
|
||
launch_template_default_tags = var.launch_template_use_default_tags ? merge(data.aws_default_tags.current.tags, var.tags) : var.tags | ||
} | ||
|
||
resource "aws_launch_template" "this" { | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above - why set on launch template explicitly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
} | ||
} | ||
|
||
|
@@ -255,6 +259,8 @@ locals { | |
launch_template_name = try(aws_launch_template.this[0].name, var.launch_template_name) | ||
# Change order to allow users to set version priority before using defaults | ||
launch_template_version = coalesce(var.launch_template_version, try(aws_launch_template.this[0].default_version, "$Default")) | ||
|
||
asg_default_tags = var.use_default_tags ? merge(data.aws_default_tags.current.tags, var.tags) : var.tags | ||
} | ||
|
||
resource "aws_autoscaling_group" "this" { | ||
|
@@ -385,7 +391,7 @@ resource "aws_autoscaling_group" "this" { | |
"kubernetes.io/cluster/${var.cluster_name}" = "owned" | ||
"k8s.io/cluster/${var.cluster_name}" = "owned" | ||
}, | ||
var.tags, | ||
local.asg_default_tags, | ||
) | ||
|
||
content { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 thethey do not get included in the tag_specifications of thelaunch_template
resource's tags,launch_template
. Those instead act much like the ASG tag specifications. Adding the ability to include the default tags to thelaunch_template
tag specifications ensures that any instances created from thelaunch_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 atags
andtag_specifications
input attribute. Thedefault_tags
do get added to thetags_all
attribute of the state, however they do not get added to thetag_specifications
that propagate down to theinstance
,network-interface
, andvolume
.There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.