Skip to content

Commit

Permalink
avoid automatic user data worker rebuild
Browse files Browse the repository at this point in the history
This buffers user data changes through a `terraform_data` resource that only
updates on Kubernetes version changes.  This allows making changes to the
user data without rebuilding the cluster unnecessarily.
  • Loading branch information
jeremy-asher committed Jun 21, 2024
1 parent 59d0ca0 commit 7e4c5cf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions eks-vpc/eks_workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ output "eks_worker_azs" {
}

locals {
num_azs = min(var.autoscaling_desired, length(local.region_availability_zones))
num_azs = min(var.autoscaling_desired, length(local.region_availability_zones))
eks_worker_azs = slice(local.region_availability_zones, 0, local.num_azs)
}

Expand Down Expand Up @@ -163,6 +163,16 @@ output "eks_worker_asg_name" {
value = local.eks_worker_asg_name
}

resource "terraform_data" "worker_user_data" {
input = base64gzip(local.user_data)

lifecycle {
ignore_changes = [input]
}

triggers_replace = [var.kubernetes_version]
}


resource "aws_launch_template" "eks_worker" {

Expand Down Expand Up @@ -190,7 +200,7 @@ resource "aws_launch_template" "eks_worker" {
instance_type = var.worker_instance_type
name_prefix = module.luthername_eks_worker_launch_template.name
vpc_security_group_ids = local.managed_nodes ? [aws_security_group.eks_worker.id] : []
user_data = base64gzip(local.user_data)
user_data = terraform_data.worker_user_data.output
key_name = local.managed_nodes ? "" : var.aws_ssh_key_name # disable ssh keys on managed nodes

dynamic "instance_market_options" {
Expand Down

0 comments on commit 7e4c5cf

Please sign in to comment.