title: Nodes are created with the same name and does not join to the EKS cluster via Terraform
body: <p>I checked all similar questions on stackoverflow but I couldn't find any decent answer for this issue. So main problem is when I applied my terraform. The instances up and run successfully and I can see the node group under EKS but I can't see any nodes under my EKS cluster. I followed this article <a href="https://aws.amazon.com/premiumsupport/knowledge-center/eks-worker-nodes-cluster/" rel="nofollow noreferrer">aws article</a> I applied below steps but didn't work. The article also mentions about aws-auth and userdata. Should I add also these things and how? (do I need userdata I already added optimized ami?)</p>
  <p>In summary my main problems:</p>
  <ol>
  <li>my instances running with same name</li>
  <li>my instances does not join the EKS cluster</li>
  </ol>
  <p>Applied steps via aws article:</p>
  <ul>
  <li><p>I added aws optimized ami but it doesn't
  solve my problem:
  <code>/aws/service/eks/optimized-ami/1.22/amazon-linux-2/recommended/image_id</code> (New update during installation of node group its failing because of this image probably not suitable for t2.micro)</p>
  </li>
  <li><p>I set below parameter for vpc what article say</p>
  <pre><code>enable_dns_support   = true 
  enable_dns_hostnames = true
  </code></pre>
  </li>
  <li><p>I set the tags for my worker nodes</p>
  <pre><code>key = &quot;kubernetes.io/cluster/${var.cluster_name}&quot;
  value = &quot;owned&quot;
  </code></pre>
  </li>
  <li><p>I specified userdata line in launch template. Below you can see my userdata.sh file that Im calling that from launch template</p>
  </li>
  </ul>
  <p><a href="https://i.stack.imgur.com/QQezg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QQezg.png" alt="enter image description here" /></a></p>
  <p>There are no nodes :(
  <a href="https://i.stack.imgur.com/uuYtA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uuYtA.png" alt="enter image description here" /></a></p>
  <p><code>node_grp.tf</code> :Here my EKS worker node terraform file with policies.</p>
  <pre><code>resource &quot;aws_iam_role&quot; &quot;eks_nodes&quot; {
    name = &quot;eks-node-group&quot;
  
    assume_role_policy = &lt;&lt;POLICY
  {
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
      {
        &quot;Effect&quot;: &quot;Allow&quot;,
        &quot;Principal&quot;: {
          &quot;Service&quot;: &quot;ec2.amazonaws.com&quot;
        },
        &quot;Action&quot;: &quot;sts:AssumeRole&quot;
      }
    ]
  }
  POLICY
  }
  
  resource &quot;aws_iam_role_policy&quot; &quot;node_autoscaling&quot; {
    name = &quot;${var.base_name}-node_autoscaling_policy&quot;
    role = aws_iam_role.eks_nodes.name
  
    policy = &lt;&lt;EOF
  {
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
      {
        &quot;Effect&quot;: &quot;Allow&quot;,
        &quot;Action&quot;: [
          &quot;autoscaling:DescribeAutoScalingGroups&quot;,
          &quot;autoscaling:DescribeAutoScalingInstances&quot;,
          &quot;autoscaling:SetDesiredCapacity&quot;,
          &quot;autoscaling:TerminateInstanceInAutoScalingGroup&quot;,
          &quot;autoscaling:DescribeTags&quot;
        ],
        &quot;Resource&quot;: &quot;*&quot;
      }
    ]
  }
  EOF
  }
  
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;AmazonEKSWorkerNodePolicy&quot; {
    policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy&quot;
    role       = aws_iam_role.eks_nodes.name
  }
  
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;AmazonEKS_CNI_Policy&quot; {
    policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy&quot;
    role       = aws_iam_role.eks_nodes.name
  }
  
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;AmazonEC2ContainerRegistryReadOnly&quot; {
    policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly&quot;
    role       = aws_iam_role.eks_nodes.name
  }
  
  resource &quot;aws_eks_node_group&quot; &quot;node&quot; {
    cluster_name    = var.cluster_name
    node_group_name = &quot;${var.base_name}-node-group&quot;
    node_role_arn   = aws_iam_role.eks_nodes.arn
    subnet_ids      = var.private_subnet_ids
  
    scaling_config {
      desired_size = var.desired_nodes
      max_size     = var.max_nodes
      min_size     = var.min_nodes
    }
  
    launch_template {
      name = aws_launch_template.node_group_template.name
      version = aws_launch_template.node_group_template.latest_version
    }
  
    depends_on = [
      aws_iam_role_policy_attachment.AmazonEKSWorkerNodePolicy,
      aws_iam_role_policy_attachment.AmazonEKS_CNI_Policy,
      aws_iam_role_policy_attachment.AmazonEC2ContainerRegistryReadOnly,
    ]
    
  }
  
  resource &quot;aws_launch_template&quot; &quot;node_group_template&quot; {
      name           = &quot;${var.cluster_name}_node_group&quot;
      instance_type  =  var.instance_type
      user_data      = base64encode(templatefile(&quot;${path.module}/userdata.sh&quot;, { API_SERVER_URL = var.cluster_endpoint, B64_CLUSTER_CA = var.ca_certificate, CLUSTER_NAME = var.cluster_name } ))
      block_device_mappings {
        device_name = &quot;/dev/xvda&quot;
  
        ebs {
          volume_size = var.disk_size
        }
      }
    
      tag_specifications {
        resource_type = &quot;instance&quot;
        tags = {
          &quot;Instance Name&quot; = &quot;${var.cluster_name}-node&quot;
          Name = &quot;${var.cluster_name}-node&quot;
          key = &quot;kubernetes.io/cluster/${var.cluster_name}&quot;
          value = &quot;owned&quot;
        }
      }
  }
  </code></pre>
  <p><code>cluster.tf</code> : my main eks cluster file</p>
  <pre><code>resource &quot;aws_iam_role&quot; &quot;eks_cluster&quot; {
    name = var.cluster_name
  
    assume_role_policy = &lt;&lt;POLICY
  {
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
      {
        &quot;Effect&quot;: &quot;Allow&quot;,
        &quot;Principal&quot;: {
          &quot;Service&quot;: &quot;eks.amazonaws.com&quot;
        },
        &quot;Action&quot;: &quot;sts:AssumeRole&quot;
      }
    ]
  }
  POLICY
  }
  
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;AmazonEKSClusterPolicy&quot; {
    policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSClusterPolicy&quot;
    role       = aws_iam_role.eks_cluster.name
  }
  
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;AmazonEKSServicePolicy&quot; {
    policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSServicePolicy&quot;
    role       = aws_iam_role.eks_cluster.name
  }
  
  resource &quot;aws_eks_cluster&quot; &quot;eks_cluster&quot; {
    name = var.cluster_name
    role_arn = aws_iam_role.eks_cluster.arn
    enabled_cluster_log_types = [&quot;api&quot;, &quot;audit&quot;, &quot;authenticator&quot;,&quot;controllerManager&quot;,&quot;scheduler&quot;]
    
  
    vpc_config {
      security_group_ids = [var.security_group_id]
      subnet_ids = flatten([ var.private_subnet_ids, var.public_subnet_ids ])
      endpoint_private_access = false
      endpoint_public_access  = true
      
    }
  
    depends_on = [
      aws_iam_role_policy_attachment.AmazonEKSClusterPolicy,
      aws_iam_role_policy_attachment.AmazonEKSServicePolicy
    ]
  }
  
  resource &quot;aws_iam_openid_connect_provider&quot; &quot;oidc_provider&quot; {
    client_id_list  = [&quot;sts.amazonaws.com&quot;]
    thumbprint_list = var.trusted_ca_thumbprints
    url             = aws_eks_cluster.eks_cluster.identity[0].oidc[0].issuer
  }
  </code></pre>
  <p><code>user-data.sh</code> : My userdata sh file calling from launch template</p>
  <pre><code>MIME-Version: 1.0
  Content-Type: multipart/mixed; boundary=&quot;==MYBOUNDARY==&quot;
  
  --==MYBOUNDARY==
  Content-Type: text/x-shellscript; charset=&quot;us-ascii&quot;
  
  #!/bin/bash
  set -ex
  /etc/eks/bootstrap.sh ${CLUSTER_NAME} --b64-cluster-ca ${B64_CLUSTER_CA} --apiserver-endpoint ${API_SERVER_URL}
  
  --==MYBOUNDARY==--\
  </code></pre>