<p>I am trying to connect terraform to a Kubernetes cluster, but the documentation on Terraform is not clear on which client certificates I should use for TLS connection. Since I am new to both Kubernetes and Terraform, I could not figure that out:</p>
<pre><code>provider &quot;kubernetes&quot; {
  host = &quot;https://xxx.xxx.xxx.xxx&quot;

  client_certificate     = &quot;${file(&quot;~/.kube/client-cert.pem&quot;)}&quot;
  client_key             = &quot;${file(&quot;~/.kube/client-key.pem&quot;)}&quot;
  cluster_ca_certificate = &quot;${file(&quot;~/.kube/cluster-ca-cert.pem&quot;)}&quot;
}
</code></pre>
<p>in the /etc/kubernetes/pki there is more than one certificate and key ( front-proxy-client, api-server-client, api-server-kubelet-client ), which one should I use to Allow terraform to connect to my cluster ?</p>
<hr />
<p><strong>Edit:</strong> Here is the kubernetes version ( output of kubectl version )</p>
<pre><code>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;22&quot;, GitVersion:&quot;v1.22.1&quot;, GitCommit:&quot;632ed300f2c34f6d6d15ca4cef3d3c7073412212&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-08-19T15:45:37Z&quot;, GoVersion:&quot;go1.16.7&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;22&quot;, GitVersion:&quot;v1.22.3&quot;, GitCommit:&quot;c92036820499fedefec0f847e2054d824aea6cd1&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-10-27T18:35:25Z&quot;, GoVersion:&quot;go1.16.9&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>

joe1531
<p>Do you have kubectl configured in the client-side where you run terraform? In that case, you can use the same configs you used for kubectl. Like this</p>
<pre><code>provider &quot;kubernetes&quot; {
  config_path    = &quot;~/.kube/config&quot;
  config_context = &quot;my-context&quot;
}

resource &quot;kubernetes_namespace&quot; &quot;example&quot; {
  metadata {
    name = &quot;my-first-namespace&quot;
  }
}
</code></pre>
<p>more details - <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#statically-defined-credentials" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#statically-defined-credentials</a></p>
<p>If not configuring kubectl is quite easy. You can refer to the docs of your flavor/version of kubernetes. You may also use the same kubeconfig file from an existing kubectl enabled client. Make sure to handle the keys securely.</p>
<p>A few different methods are mentioned here - <a href="https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider?in=terraform/use-case#configure-the-provider" rel="nofollow noreferrer">https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider?in=terraform/use-case#configure-the-provider</a></p>
<p>If you are using a cloud provider flavor like EKS, gcloud you explore the cloud-specific plugins too.</p>
