terraform-aws-modules/terraform-aws-eks

Trying to use custom template gives error

rmalenko opened this issue · 6 comments

I would like to use a custom template, but I have got this error. Did I correctly prepare config to use custom template?

  ╷
  │ Error: Invalid value for input variable
  │
  │   on ../../modules/aws-eks/node_groups.tf line 350, in module "eks_managed_node_group":
  │  350:   launch_template_id                     = try(each.value.launch_template_id, var.eks_managed_node_group_defaults.launch_template_id, "")
  │
  │ The given value is not suitable for
  │ module.eks.module.eks_managed_node_group["example"].var.launch_template_id
  │ declared at
  │ ../../modules/aws-eks/modules/eks-managed-node-group/variables.tf:122,1-30:
  │ string required.
  ╵
  ╷
  │ Error: Invalid value for input variable
  │
  │   on ../../modules/aws-eks/node_groups.tf line 351, in module "eks_managed_node_group":
  │  351:   launch_template_name                   = try(each.value.launch_template_name, var.eks_managed_node_group_defaults.launch_template_name, each.key)
  │
  │ The given value is not suitable for
  │ module.eks.module.eks_managed_node_group["example"].var.launch_template_name
  │ declared at
  │ ../../modules/aws-eks/modules/eks-managed-node-group/variables.tf:128,1-32:
  │ string required.
  ╵
...
  eks_managed_node_groups = {
    example = {
      # Starting on 1.30, AL2023 is the default AMI type for EKS managed node groups
      ami_type       = "AL2023_x86_64_STANDARD"
      instance_types = ["m5.xlarge"]

      create_launch_template                 = false
      use_custom_launch_template             = true
      update_launch_template_default_version = false
      launch_template_id                     = data.terraform_remote_state.ec2_template.outputs.launch_template_id
      launch_template_name                   = data.terraform_remote_state.ec2_template.outputs.launch_template_name

      min_size     = 2
      max_size     = 3
      desired_size = 2
    }
  }
...
18:43:05.101 STDOUT terraform: Changes to Outputs:
18:43:05.101 STDOUT terraform:   + template_id   = {
18:43:05.102 STDOUT terraform:       + jazzfest-eks-rnd = "lt-008ef9b16aac82670"
18:43:05.102 STDOUT terraform:     }
18:43:05.102 STDOUT terraform:   + template_name = {
18:43:05.102 STDOUT terraform:       + jazzfest-eks-rnd = "jazzfest-eks-rnd-eks"
18:43:05.102 STDOUT terraform:     }

use launch_template_id or launch_template_name, but not both - launch_template_id would be the recommended route

use launch_template_id or launch_template_name, but not both - launch_template_id would be the recommended route

Thank you for your reply. I have already tried launch_template_id alone and got the same error.

Similar to this I am getting errors:

With this approach:

test_launch_template = {
        name                       = "${local.hybrid_cluster_name}"
        iam_role_use_name_prefix   = false
        iam_role_name              = "${local.hybrid_cluster_name}"
        create_launch_template     = false
        use_custom_launch_template = true
        launch_template_id         = aws_launch_template.platform_linux.id
        launch_template_version    = aws_launch_template.platform_linux.latest_version
        force_update_version       = true
        min_size                   = 2
        max_size                   = 4
        desired_size               = 2
        tags = merge(local.tags, {
          "karpenter.sh/discovery" = local.hybrid_cluster_name
        })
        block_device_mappings = {
          xvda = {
            device_name = "/dev/xvda"
            ebs = {
              volume_size = 30
              volume_type = "gp3"
              encrypted   = true
            }
          }
        }
      }

I am getting error:
You cannot specify a kubernetes version to use when specifying an image id to use within the launch template.
With this approach:

test_launch_template = {
        name                       = "${local.hybrid_cluster_name}"
        iam_role_use_name_prefix   = false
        iam_role_name              = "${local.hybrid_cluster_name}"
        ami_id                          = data.aws_ami.custom_linux_ami.id
        force_update_version       = true
        min_size                   = 2
        max_size                   = 4
        desired_size               = 2
        tags = merge(local.tags, {
          "karpenter.sh/discovery" = local.hybrid_cluster_name
        })
        block_device_mappings = {
          xvda = {
            device_name = "/dev/xvda"
            ebs = {
              volume_size = 30
              volume_type = "gp3"
              encrypted   = true
            }
          }
        }
      }

I am getting error:

InvalidParameterException: You cannot specify an image id within the launch template, since your nodegroup is configured to use an EKS optimized AMI.

Module Version: ~> 20.23.0

I'll have to take a look later with something that is deployable - however, I am curious as to why a custom/external launch template is desired over the custom launch template that is threaded into this module (since its designed and tested to avoid known footguns and does work as intended)

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days