From 291364c0c3182ebef52b9c1644100bc7b88500d3 Mon Sep 17 00:00:00 2001 From: Albin Gustavsson Date: Thu, 6 Jul 2023 15:33:37 +0200 Subject: [PATCH] Add option to set instance_type on the launch template This allows setting the instance type on the launch template rather than the EKS Managed node group. This is useful because it is not possible to change the instance types set on a managed node groups after creation. The suggested way to work around this is to simply define the instance type in the launch template. https://github.com/aws/containers-roadmap/issues/746#issuecomment-675099508 --- modules/eks-managed-node-group/main.tf | 2 ++ modules/eks-managed-node-group/variables.tf | 8 +++++++- node_groups.tf | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/eks-managed-node-group/main.tf b/modules/eks-managed-node-group/main.tf index 1d3fe81698..035b428d6c 100644 --- a/modules/eks-managed-node-group/main.tf +++ b/modules/eks-managed-node-group/main.tf @@ -170,6 +170,8 @@ resource "aws_launch_template" "this" { } } + instance_type = var.instance_type + # # Set on node group instead # instance_type = var.launch_template_instance_type kernel_id = var.kernel_id diff --git a/modules/eks-managed-node-group/variables.tf b/modules/eks-managed-node-group/variables.tf index 197cd28c95..161d940750 100644 --- a/modules/eks-managed-node-group/variables.tf +++ b/modules/eks-managed-node-group/variables.tf @@ -222,6 +222,12 @@ variable "instance_market_options" { default = {} } +variable "instance_type" { + description = "Set of instance type associated with the Launch Template. Conflicts with `instance_types`" + type = string + default = null +} + variable "maintenance_options" { description = "The maintenance options for the instance" type = any @@ -351,7 +357,7 @@ variable "force_update_version" { } variable "instance_types" { - description = "Set of instance types associated with the EKS Node Group. Defaults to `[\"t3.medium\"]`" + description = "Set of instance types associated with the EKS Node Group. Defaults to `[\"t3.medium\"]`. Conflicts with `instance_types`" type = list(string) default = null } diff --git a/node_groups.tf b/node_groups.tf index db78861a81..96bf0ca799 100644 --- a/node_groups.tf +++ b/node_groups.tf @@ -341,6 +341,7 @@ module "eks_managed_node_group" { elastic_inference_accelerator = try(each.value.elastic_inference_accelerator, var.eks_managed_node_group_defaults.elastic_inference_accelerator, {}) enclave_options = try(each.value.enclave_options, var.eks_managed_node_group_defaults.enclave_options, {}) instance_market_options = try(each.value.instance_market_options, var.eks_managed_node_group_defaults.instance_market_options, {}) + instance_type = try(each.value.instance_type, var.eks_managed_node_group_defaults.instance_type, null) license_specifications = try(each.value.license_specifications, var.eks_managed_node_group_defaults.license_specifications, {}) metadata_options = try(each.value.metadata_options, var.eks_managed_node_group_defaults.metadata_options, local.metadata_options) enable_monitoring = try(each.value.enable_monitoring, var.eks_managed_node_group_defaults.enable_monitoring, true)