Skip to content

Commit ce19790

Browse files
raizyrspr-mweber3
authored andcommitted
feat: Support default_tags in aws_autoscaling_group (terraform-aws-modules#1973)
1 parent 7f1ce1a commit ce19790

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

examples/complete/main.tf

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
provider "aws" {
22
region = local.region
3+
4+
default_tags {
5+
tags = {
6+
ExampleDefaultTag = "ExampleDefaultValue"
7+
}
8+
}
39
}
410

511
locals {
@@ -216,6 +222,8 @@ module "self_managed_node_group" {
216222
module.eks.cluster_security_group_id,
217223
]
218224

225+
use_default_tags = true
226+
219227
tags = merge(local.tags, { Separate = "self-managed-node-group" })
220228
}
221229

modules/self-managed-node-group/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module "self_managed_node_group" {
6868
| [aws_security_group_rule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
6969
| [aws_ami.eks_default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
7070
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
71+
| [aws_default_tags.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/default_tags) | data source |
7172
| [aws_iam_policy_document.assume_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
7273
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
7374

@@ -161,6 +162,7 @@ module "self_managed_node_group" {
161162
| <a name="input_target_group_arns"></a> [target\_group\_arns](#input\_target\_group\_arns) | A set of `aws_alb_target_group` ARNs, for use with Application or Network Load Balancing | `list(string)` | `[]` | no |
162163
| <a name="input_termination_policies"></a> [termination\_policies](#input\_termination\_policies) | A list of policies to decide how the instances in the Auto Scaling Group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `OldestLaunchTemplate`, `AllocationStrategy`, `Default` | `list(string)` | `null` | no |
163164
| <a name="input_update_launch_template_default_version"></a> [update\_launch\_template\_default\_version](#input\_update\_launch\_template\_default\_version) | Whether to update Default Version each update. Conflicts with `launch_template_default_version` | `bool` | `true` | no |
165+
| <a name="input_use_default_tags"></a> [use\_default\_tags](#input\_use\_default\_tags) | Enables/disables the use of provider default tags in the tag\_specifications of the Auto Scaling group | `bool` | `false` | no |
164166
| <a name="input_use_mixed_instances_policy"></a> [use\_mixed\_instances\_policy](#input\_use\_mixed\_instances\_policy) | Determines whether to use a mixed instances policy in the autoscaling group or not | `bool` | `false` | no |
165167
| <a name="input_use_name_prefix"></a> [use\_name\_prefix](#input\_use\_name\_prefix) | Determines whether to use `name` as is or create a unique name beginning with the `name` as the prefix | `bool` | `true` | no |
166168
| <a name="input_user_data_template_path"></a> [user\_data\_template\_path](#input\_user\_data\_template\_path) | Path to a local, custom user data template file to use when rendering user data | `string` | `""` | no |

modules/self-managed-node-group/main.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ data "aws_partition" "current" {}
22

33
data "aws_caller_identity" "current" {}
44

5+
data "aws_default_tags" "current" {}
6+
57
data "aws_ami" "eks_default" {
68
count = var.create ? 1 : 0
79

@@ -385,7 +387,7 @@ resource "aws_autoscaling_group" "this" {
385387
"kubernetes.io/cluster/${var.cluster_name}" = "owned"
386388
"k8s.io/cluster/${var.cluster_name}" = "owned"
387389
},
388-
var.tags,
390+
var.use_default_tags ? merge(data.aws_default_tags.current.tags, var.tags) : var.tags
389391
)
390392

391393
content {

modules/self-managed-node-group/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ variable "delete_timeout" {
452452
default = null
453453
}
454454

455+
variable "use_default_tags" {
456+
description = "Enables/disables the use of provider default tags in the tag_specifications of the Auto Scaling group"
457+
type = bool
458+
default = false
459+
}
460+
455461
################################################################################
456462
# Autoscaling group schedule
457463
################################################################################

node_groups.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ module "self_managed_node_group" {
381381
create_schedule = try(each.value.create_schedule, var.self_managed_node_group_defaults.create_schedule, false)
382382
schedules = try(each.value.schedules, var.self_managed_node_group_defaults.schedules, null)
383383

384-
delete_timeout = try(each.value.delete_timeout, var.self_managed_node_group_defaults.delete_timeout, null)
384+
delete_timeout = try(each.value.delete_timeout, var.self_managed_node_group_defaults.delete_timeout, null)
385+
use_default_tags = try(each.value.use_default_tags, var.self_managed_node_group_defaults.use_default_tags, false)
385386

386387
# User data
387388
platform = try(each.value.platform, var.self_managed_node_group_defaults.platform, "linux")

0 commit comments

Comments
 (0)