<p>I'm trying to make a simple test to build a simple nginx on kubernetes from terraform.
This is the first time working terraform.</p>

<p>This is the basic terraform file:</p>

<pre><code>provider "kubernetes" {
  host = "https://xxx.xxx.xxx.xxx:8443"

  client_certificate     = "${file("~/.kube/master.server.crt")}"
  client_key             = "${file("~/.kube/master.server.key")}"
  cluster_ca_certificate = "${file("~/.kube/ca.crt")}"

  username = "xxxxxx"
  password = "xxxxxx"

}

resource "kubernetes_service" "nginx" {
  metadata {
    name = "nginx-example"
  }
  spec {
    selector {
      App = "${kubernetes_pod.nginx.metadata.0.labels.App}"
    }
    port {
      port = 80
      target_port = 80
    }

    type = "LoadBalancer"
  }
}

resource "kubernetes_pod" "nginx" {
  metadata {
    name = "nginx-example"
    labels {
      App = "nginx"
    }
  }

  spec {
    container {
      image = "nginx:1.7.8"
      name  = "example"

      port {
        container_port = 80
      }
    }
  }
}
</code></pre>

<p>I'm getting the following error after running the terraform apply.</p>

<blockquote>
  <p>Error: Error applying plan:</p>
  
  <p>1 error(s) occurred:</p>
  
  <ul>
  <li><p>kubernetes_pod.nginx: 1 error(s) occurred:</p></li>
  <li><p>kubernetes_pod.nginx: the server has asked for the client to provide credentials (post pods)</p></li>
  </ul>
  
  <p>Terraform does not automatically rollback in the face of errors.
  Instead, your Terraform state file has been partially updated with any
  resources that successfully completed. Please address the error above
  and apply again to incrementally change your infrastructure.</p>
</blockquote>

<p>I have admin permissions on kubernetes and everything is working correctly.
But for some reason I'm getting that error.</p>

<p>What I'm doing wrong?</p>

<p>Thanks</p>

<p><strong>Regarding @matthew-l-daniel question</strong></p>

<p>When I'm only using the username/password I get this error:</p>

<blockquote>
  <p>Error: Error applying plan:</p>
  
  <p>1 error(s) occurred:</p>
  
  <ul>
  <li><p>kubernetes_pod.nginx: 1 error(s) occurred:</p></li>
  <li><p>kubernetes_pod.nginx: Post <a href="https://xxx.xxx.xxx.xxx:8443/api/v1/namespaces/default/pods" rel="noreferrer">https://xxx.xxx.xxx.xxx:8443/api/v1/namespaces/default/pods</a>:
  x509: certificate signed by unknown authority</p></li>
  </ul>
  
  <p>Terraform does not automatically rollback in the face of errors.
  Instead, your Terraform state file has been partially updated with any
  resources that successfully completed. Please address the error above
  and apply again to incrementally change your infrastructure.</p>
</blockquote>

<p>I tried using the server name or the server ip and got the same error everytime.</p>

<p>When using the certs I got the error from the original post, regarding the "credentials"</p>

<p>I forgot to mention that this is an openshift installation. I don't believe it will have any impact in the end, but I thought I should mention it.</p>

<p>The solution was rather simple, I was using the master crt and key from openshift on terraform.
Then I tested it using the admin crt and key from openshift and it worked.</p>
