<p>I'm using Terraform to provision an EKS cluster (mostly following the example <a href="https://learn.hashicorp.com/terraform/aws/eks-intro" rel="nofollow noreferrer">here</a>). At the end of the tutorial, there's a method of outputting the configmap through the <code>terraform output</code> command, and then applying it to the cluster via <code>kubectl apply -f &lt;file&gt;</code>. I'm attempting to wrap this <code>kubectl</code> command into the Terraform file using the <code>kubernetes_config_map</code> resource, however when running Terraform for the first time, I receive the following error:</p>

<pre><code>Error: Error applying plan:

1 error(s) occurred:

* kubernetes_config_map.config_map_aws_auth: 1 error(s) occurred:

* kubernetes_config_map.config_map_aws_auth: the server could not find the requested resource (post configmaps)
</code></pre>

<p>The strange thing is, every subsequent <code>terraform apply</code> works, and applies the configmap to the EKS cluster. This leads me to believe it is perhaps a timing issue? I tried to preform a bunch of actions in between the provisioning of the cluster and applying the configmap but that didn't work. I also put an explicit <code>depends_on</code> argument to ensure that the cluster has been fully provisioned first before attempting to apply the configmap.</p>

<pre><code>provider "kubernetes" {
  config_path = "kube_config.yaml"
}

locals {
  map_roles = &lt;&lt;ROLES
- rolearn: ${aws_iam_role.eks_worker_iam_role.arn}
  username: system:node:{{EC2PrivateDNSName}}
  groups:
    - system:bootstrappers
    - system:nodes
ROLES
}

resource "kubernetes_config_map" "config_map_aws_auth" {
  metadata {
    name      = "aws-auth"
    namespace = "kube-system"
  }

  data {
    mapRoles = "${local.map_roles}"
  }

  depends_on = ["aws_eks_cluster.eks_cluster"]
}
</code></pre>

<p>I expect for this to run correctly the first time, however it only runs after applying the same file with no changes a second time. </p>

<p>I attempted to get more information by enabling the <code>TRACE</code> debug flag for terraform, however the only output I got was the exact same error as above.</p>

jcploucha
<p>Well, I don't know if that is fresh yet but I was dealing with the same troubles and found out that:</p>
<p><a href="https://github.com/terraform-aws-modules/terraform-aws-eks/issues/699#issuecomment-601136543" rel="nofollow noreferrer">https://github.com/terraform-aws-modules/terraform-aws-eks/issues/699#issuecomment-601136543</a></p>
<p>So, in others words, I changed the cluster's name in <strong>aws_eks_cluster_auth</strong> block to a <strong>static name</strong>, and worked. Well, perhaps this is a bug on TF.</p>
