<p>I would like to manage configuration for a service using terraform to a GKE cluster defined using external terraform script.</p>
<p>I created the configuration using <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret" rel="nofollow noreferrer"><code>kubernetes_secret</code></a>.</p>
<p>Something like below</p>
<pre><code>resource &quot;kubernetes_secret&quot; &quot;service_secret&quot; {
  metadata {
    name = &quot;my-secret&quot;
    namespace = &quot;my-namespace&quot;
  }  

  data = {
    username = &quot;admin&quot;
    password = &quot;P4ssw0rd&quot;
  }
}
</code></pre>
<p>And I also put this google client configuration to configure the kubernetes provider.</p>
<pre><code>data &quot;google_client_config&quot; &quot;current&quot; {

}

data &quot;google_container_cluster&quot; &quot;cluster&quot; {
  name = &quot;my-container&quot;
  location = &quot;asia-southeast1&quot;
  zone = &quot;asia-southeast1-a&quot;
}

provider &quot;kubernetes&quot; {
  host                   = &quot;https://${data.google_container_cluster.cluster.endpoint}&quot;
  token                  = data.google_client_config.current.access_token
  cluster_ca_certificate = base64decode(data.google_container_cluster.cluster.master_auth[0].cluster_ca_certificate)
}
</code></pre>
<p>when I apply the terraform it shows error message below</p>
<p><a href="https://i.stack.imgur.com/JeROi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JeROi.png" alt="error" /></a></p>
<p><code>data.google_container_cluster.cluster.endpoint is null</code></p>
<p>Do I miss some steps here?</p>

Petra Barus
<p>I just had the same/similar issue when trying to initialize the kubernetes provider from a google_container_cluster data source. <code>terraform show</code> just displayed all null values for the data source attributes. The fix for me was to specify the project in the data source, e.g.,</p>
<pre><code>data &quot;google_container_cluster&quot; &quot;cluster&quot; {
  name     = &quot;my-container&quot;
  location = &quot;asia-southeast1&quot;
  zone     = &quot;asia-southeast1-a&quot;
  project  = &quot;my-project&quot;
}
</code></pre>
<p><a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster#project" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster#project</a></p>
<blockquote>
<p>project - (Optional) The project in which the resource belongs. If it is not provided, the provider project is used.</p>
</blockquote>
<p>In my case the google provider was pointing to a different project than the one containing the cluster I wanted to get info about.</p>
<p>In addition, you should be able to remove the <code>zone</code> attribute from that block. <code>location</code> should refer to the zone if it is a zonal cluster or the region if it is a regional cluster.</p>
