Skip to content

Commit

Permalink
fix: Update autoscaling group tags -> tag to support v4 of AWS pr…
Browse files Browse the repository at this point in the history
…ovider (#1866)
  • Loading branch information
baibailiha authored Aug 17, 2023
1 parent 432c485 commit 1892b1e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 55 deletions.
19 changes: 3 additions & 16 deletions examples/irsa_autoscale_refresh/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ module "eks" {
triggers = ["tag"]
}

propogate_tags = [{
key = "aws-node-termination-handler/managed"
value = true
propagate_at_launch = true
}]
tags = { "aws-node-termination-handler/managed" = "true" }
}

mixed_instance = {
Expand All @@ -82,11 +78,7 @@ module "eks" {
]
}

propogate_tags = [{
key = "aws-node-termination-handler/managed"
value = true
propagate_at_launch = true
}]
tags = { "aws-node-termination-handler/managed" = "true" }
}

spot = {
Expand All @@ -96,12 +88,7 @@ module "eks" {
}

bootstrap_extra_args = "--kubelet-extra-args '--node-labels=node.kubernetes.io/lifecycle=spot'"

propogate_tags = [{
key = "aws-node-termination-handler/managed"
value = true
propagate_at_launch = true
}]
tags = { "aws-node-termination-handler/managed" = "true" }
}
}

Expand Down
3 changes: 1 addition & 2 deletions modules/self-managed-node-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module "self_managed_node_group" {
| <a name="input_cluster_auth_base64"></a> [cluster\_auth\_base64](#input\_cluster\_auth\_base64) | Base64 encoded CA of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_endpoint"></a> [cluster\_endpoint](#input\_cluster\_endpoint) | Endpoint of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_ip_family"></a> [cluster\_ip\_family](#input\_cluster\_ip\_family) | The IP family used to assign Kubernetes pod and service addresses. Valid values are `ipv4` (default) and `ipv6` | `string` | `null` | no |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of associated EKS cluster | `string` | `null` | no |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of associated EKS cluster | `string` | `""` | no |
| <a name="input_cluster_security_group_id"></a> [cluster\_security\_group\_id](#input\_cluster\_security\_group\_id) | Cluster control plane security group ID | `string` | `null` | no |
| <a name="input_cluster_version"></a> [cluster\_version](#input\_cluster\_version) | Kubernetes cluster version - used to lookup default AMI ID if one is not provided | `string` | `null` | no |
| <a name="input_cpu_options"></a> [cpu\_options](#input\_cpu\_options) | The CPU options for the instance | `map(string)` | `null` | no |
Expand Down Expand Up @@ -146,7 +146,6 @@ module "self_managed_node_group" {
| <a name="input_platform"></a> [platform](#input\_platform) | Identifies if the OS platform is `bottlerocket`, `linux`, or `windows` based | `string` | `"linux"` | no |
| <a name="input_post_bootstrap_user_data"></a> [post\_bootstrap\_user\_data](#input\_post\_bootstrap\_user\_data) | User data that is appended to the user data script after of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
| <a name="input_pre_bootstrap_user_data"></a> [pre\_bootstrap\_user\_data](#input\_pre\_bootstrap\_user\_data) | User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
| <a name="input_propagate_tags"></a> [propagate\_tags](#input\_propagate\_tags) | A list of tag blocks. Each element should have keys named `key`, `value`, and `propagate_at_launch` | `list(map(string))` | `[]` | no |
| <a name="input_protect_from_scale_in"></a> [protect\_from\_scale\_in](#input\_protect\_from\_scale\_in) | Allows setting instance protection. The autoscaling group will not select instances with this setting for termination during scale in events. | `bool` | `false` | no |
| <a name="input_ram_disk_id"></a> [ram\_disk\_id](#input\_ram\_disk\_id) | The ID of the ram disk | `string` | `null` | no |
| <a name="input_schedules"></a> [schedules](#input\_schedules) | Map of autoscaling group schedule to create | `map(any)` | `{}` | no |
Expand Down
45 changes: 17 additions & 28 deletions modules/self-managed-node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,23 @@ resource "aws_autoscaling_group" "this" {
}
}

dynamic "tag" {
for_each = merge(
{
"Name" = var.name
"kubernetes.io/cluster/${var.cluster_name}" = "owned"
"k8s.io/cluster/${var.cluster_name}" = "owned"
},
var.tags,
)

content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}

timeouts {
delete = var.delete_timeout
}
Expand All @@ -388,34 +405,6 @@ resource "aws_autoscaling_group" "this" {
desired_capacity
]
}

tags = concat(
[
{
key = "Name"
value = var.name
propagate_at_launch = true
},
{
key = "kubernetes.io/cluster/${var.cluster_name}"
value = "owned"
propagate_at_launch = true
},
{
key = "k8s.io/cluster/${var.cluster_name}"
value = "owned"
propagate_at_launch = true
},
],
var.propagate_tags,
[for k, v in var.tags :
{
key = k
value = v
propagate_at_launch = true
}
]
)
}

################################################################################
Expand Down
8 changes: 1 addition & 7 deletions modules/self-managed-node-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ variable "platform" {
variable "cluster_name" {
description = "Name of associated EKS cluster"
type = string
default = null
default = ""
}

variable "cluster_endpoint" {
Expand Down Expand Up @@ -446,12 +446,6 @@ variable "delete_timeout" {
default = null
}

variable "propagate_tags" {
description = "A list of tag blocks. Each element should have keys named `key`, `value`, and `propagate_at_launch`"
type = list(map(string))
default = []
}

################################################################################
# Autoscaling group schedule
################################################################################
Expand Down
3 changes: 1 addition & 2 deletions node_groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,5 @@ module "self_managed_node_group" {
security_group_rules = try(each.value.security_group_rules, var.self_managed_node_group_defaults.security_group_rules, {})
security_group_tags = try(each.value.security_group_tags, var.self_managed_node_group_defaults.security_group_tags, {})

tags = merge(var.tags, try(each.value.tags, var.self_managed_node_group_defaults.tags, {}))
propagate_tags = try(each.value.propagate_tags, var.self_managed_node_group_defaults.propagate_tags, [])
tags = merge(var.tags, try(each.value.tags, var.self_managed_node_group_defaults.tags, {}))
}

0 comments on commit 1892b1e

Please sign in to comment.