<p>I'm using terraform v0.14.2 , and I'm trying to create a EKS cluster but I'm having problem when the nodes are joining to the cluster. The status stay stucked in &quot;Creating&quot; until get an error:</p>
<p>My code to deploy is:</p>
<blockquote>
<p>Error: error waiting for EKS Node Group (EKS_SmartSteps:EKS_SmartSteps-worker-node-uk) creation: NodeCreationFailure: Instances failed to join the kubernetes cluster. Resource IDs: [i-00c4bac08b3c42225]</p>
</blockquote>
<pre><code>resource &quot;aws_eks_node_group&quot; &quot;managed_workers&quot; {
  for_each        = local.ob

  cluster_name    = aws_eks_cluster.cluster.name
  node_group_name = &quot;${var.cluster_name}-worker-node-${each.value}&quot;
  node_role_arn   = aws_iam_role.managed_workers.arn
  subnet_ids      = aws_subnet.private.*.id
  scaling_config {
    desired_size = 1
    max_size     = 1
    min_size     = 1
  }
  launch_template {
    id      = aws_launch_template.worker-node[each.value].id
    version = aws_launch_template.worker-node[each.value].latest_version
  }

  depends_on = [
    kubernetes_config_map.aws_auth_configmap,
    aws_iam_role_policy_attachment.eks-AmazonEKSWorkerNodePolicy,
    aws_iam_role_policy_attachment.eks-AmazonEKS_CNI_Policy,
    aws_iam_role_policy_attachment.eks-AmazonEC2ContainerRegistryReadOnly,
  ]
  lifecycle {
    create_before_destroy = true
    ignore_changes = [scaling_config[0].desired_size, scaling_config[0].min_size]
  }
}

resource &quot;aws_launch_template&quot; &quot;worker-node&quot; {
  for_each               = local.ob

  image_id               = data.aws_ssm_parameter.cluster.value
  name                   = &quot;${var.cluster_name}-worker-node-${each.value}&quot;
  instance_type          = &quot;t3.medium&quot;

  block_device_mappings {
    device_name = &quot;/dev/xvda&quot;

    ebs {
      volume_size = 20
      volume_type = &quot;gp2&quot;
    }
  }
  tag_specifications {
    resource_type = &quot;instance&quot;
    tags = {
      &quot;Instance Name&quot; = &quot;${var.cluster_name}-node-${each.value}&quot;
       Name = &quot;${var.cluster_name}-node-${each.value}&quot;
    }
  }
}
</code></pre>
<p>In fact, I see in the EC2 instances and EKS the nodes attached to the EKS cluster, but with this status error:</p>
<blockquote>
<p>&quot;Instances failed to join the kubernetes cluster&quot;</p>
</blockquote>
<p>I cant inspect where is the error because the error messages dont show more info..</p>
<p>Any idea?</p>
<p>thx</p>

Humberto Lantero
<p>So others can follow, you need to include a user data script to get the nodes to join the cluster.  Something like:</p>
<p>userdata.tpl</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>
<p>Where you render it like so</p>
<pre><code>locals {
  user_data_values = {
    CLUSTER_NAME = var.cluster_name
    B64_CLUSTER_CA = var.cluster_certificate_authority
    API_SERVER_URL = var.cluster_endpoint
  }
}

resource &quot;aws_launch_template&quot; &quot;cluster&quot; {
  image_id  = &quot;ami-XXX&quot; # Make sure the AMI is an EKS worker
  user_data = base64encode(templatefile(&quot;userdata.tpl&quot;, local.user_data_values))
...
}
</code></pre>
<p>Aside from that, make sure the node group is part of the worker security group and has the required IAM roles and you should be fine.</p>
