Home > Blockchain >  You cannot specify an AMI Type other than CUSTOM, when specifying an image id in your launch templat
You cannot specify an AMI Type other than CUSTOM, when specifying an image id in your launch templat

Time:07-02

I'm stuck in a loop here- I'm trying to create a launch template for my eks nodes and my launch template looked like this:

resource "aws_launch_template" "node" {
  image_id                             = var.image_id
  instance_type                        = var.instance_type
  key_name                             = var.key_name
  instance_initiated_shutdown_behavior = "terminate"
  name                                 = var.name
  user_data                            = base64encode("node_userdata.tpl")
#   vpc_security_group_ids               = var.security_group_ids

    block_device_mappings {
        device_name = "/dev/sda1"

    ebs {
      volume_size = 20
    }
  }

  iam_instance_profile {
    name = aws_iam_instance_profile.node.name
  }

  monitoring {
    enabled = true
  }
}

Here's my node resource block as well:

resource "aws_eks_node_group" "nodes_eks" {

  cluster_name    = aws_eks_cluster.eks.name
  node_group_name = "eks-node-group"
  node_role_arn   = aws_iam_role.eks_nodes.arn
  subnet_ids      = module.vpc.private_subnets
  # remote_access {
  #   ec2_ssh_key = aws_key_pair.bastion_auth.id

  # }

  scaling_config {
    desired_size = 3
    max_size     = 6
    min_size     = 3
  }

  ami_type             = "AL2_x86_64"
  capacity_type        = "ON_DEMAND"

  force_update_version = false
  instance_types       = [var.instance_type]
  labels = {
    role = "nodes-pool-1"
  }

  launch_template {
    id = aws_launch_template.node.id
    version = "$Default"
  }

  # version = var.k8s_version

  depends_on = [
    aws_iam_role_policy_attachment.amazon_eks_worker_node_policy,
    aws_iam_role_policy_attachment.amazon_eks_cni_policy,
    aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only,
  ]
}

My image ID for my launch template is this amazon linux 2 image "ami-098e42ae54c764c35". When I tried to run that, it gave me this error

You cannot specify an AMI Type other than CUSTOM, when specifying an image id in your launch template

So I changed it from var.image_id (The Amazon Linux 2 image) to "CUSTOM" and it's returning this error now:

InvalidAMIID.Malformed: The image ID 'CUSTOM' is not valid. The expected format is ami-xxxxxxxx or ami-xxxxxxxxxxxxxxxxx.

I don't know what the solution is, because when I passed in the ami via a variable it said the value had to be "CUSTOM", so I made it that and now it's saying it has to be the typical AMI id format.

CodePudding user response:

You cannot have both the ami_type = "AL2_x86_64" and launch_configuration. The message is a bit misleading, but if you look in [1], you will see where CUSTOM has to be used:

If the node group was deployed using a launch template with a custom AMI, then this is CUSTOM.

So, you have to change the following line:

ami_type = "CUSTOM"

Also, the Terraform docs [2] have something to say about fetching the version of the launch template. The final outlook of your launch_configuration block should be:

  launch_template {
    id      = aws_launch_template.node.id
    version = aws_launch_template.node.latest_version
  }

[1] https://docs.aws.amazon.com/eks/latest/APIReference/API_Nodegroup.html#AmazonEKS-Type-Nodegroup-amiType

[2] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group#version

  • Related