<p>Following this tutorial,
<a href="https://learn.hashicorp.com/tutorials/terraform/gke?in=terraform/kubernetes" rel="nofollow noreferrer">https://learn.hashicorp.com/tutorials/terraform/gke?in=terraform/kubernetes</a>
I have deployed a GKE cluster in GCloud.</p>
<p>Now when I try to schedule a deployment following this link,
<a href="https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider" rel="nofollow noreferrer">https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider</a></p>
<p>It fails with,</p>
<pre><code>kubernetes_deployment.nginx: Creating...

Error: Failed to create deployment: Post &quot;https://&lt;ip&gt;/apis/apps/v1/namespaces/default/deployments&quot;: x509: certificate signed by unknown authority

  on kubernetes.tf line 21, in resource &quot;kubernetes_deployment&quot; &quot;nginx&quot;:
  21: resource &quot;kubernetes_deployment&quot; &quot;nginx&quot; {
</code></pre>
<p>My kubernetes.tf looks like this,</p>
<pre><code>terraform {
  required_providers {
    kubernetes = {
      source = &quot;hashicorp/kubernetes&quot;
    }
  }
}

provider &quot;kubernetes&quot; {
  load_config_file = false

  host     = google_container_cluster.primary.endpoint
  username = var.gke_username
  password = var.gke_password

  client_certificate     = google_container_cluster.primary.master_auth.0.client_certificate
  client_key             = google_container_cluster.primary.master_auth.0.client_key
  cluster_ca_certificate = google_container_cluster.primary.master_auth.0.cluster_ca_certificate
}

resource &quot;kubernetes_deployment&quot; &quot;nginx&quot; {
  metadata {
    name = &quot;scalable-nginx-example&quot;
    labels = {
      App = &quot;ScalableNginxExample&quot;
    }
  }

  spec {
    replicas = 2
    selector {
      match_labels = {
        App = &quot;ScalableNginxExample&quot;
      }
    }
    template {
      metadata {
        labels = {
          App = &quot;ScalableNginxExample&quot;
        }
      }
      spec {
        container {
          image = &quot;nginx:1.7.8&quot;
          name  = &quot;example&quot;

          port {
            container_port = 80
          }

          resources {
            limits {
              cpu    = &quot;0.5&quot;
              memory = &quot;512Mi&quot;
            }
            requests {
              cpu    = &quot;250m&quot;
              memory = &quot;50Mi&quot;
            }
          }
        }
      }
    }
  }
}
</code></pre>
<p>I am using MacOS to run terraform. Any help is appreciated.</p>
<p>Please note that kubectl get pods --all-namespaces is working fine, so I don't think it's an issue with kube config.</p>
<p>Thanks,
Arun</p>

Arun A Nayagam
<p>It was because the certificate was base64 encoded, changing the provider section to the below snippet, got rid of the issue.</p>
<pre><code>provider &quot;kubernetes&quot; {
  load_config_file = false

  host     = google_container_cluster.primary.endpoint
  username = var.gke_username
  password = var.gke_password

  client_certificate     = base64decode(google_container_cluster.primary.master_auth.0.client_certificate)
  client_key             = base64decode(google_container_cluster.primary.master_auth.0.client_key)
  cluster_ca_certificate = base64decode(google_container_cluster.primary.master_auth.0.cluster_ca_certificate)
}
</code></pre>
