<p>In my terraform project, I have my own module which creates an AKS cluster with RBAC enabled. This module has an output <strong>aks_public_fqdn</strong> which holds the FQDN of the cluster.</p>
<pre><code>module &quot;aks&quot; {
  source = &quot;./aks&quot;

  environment        = local.environment
  region             = local.region
  instance_id        = local.workload_id
  application        = local.workload_name
  resource_group     = local.rg_name
  kubernetes_version = local.kubernetes_version

}
</code></pre>
<p>Once the cluster is up and running, I would like to create some K8S resources through Terraform with the Kubernetes provider.</p>
<p>To authenticate I am using the following code snippet:</p>
<pre><code>provider &quot;kubernetes&quot; {
  host                   = &quot;https://${module.aks.aks_public_fqdn}&quot;
  insecure = true

  exec {
    api_version = &quot;client.authentication.k8s.io/v1beta1&quot;
    command     = &quot;kubelogin&quot;
    args = [
      &quot;get-token&quot;,
      &quot;--environment&quot;,
      &quot;AzurePublicCloud&quot;,
      &quot;--server-id&quot;,
      &quot;3333333-3333333-3333333&quot;,
      &quot;--login&quot;,
      &quot;azurecli&quot;
    ]
  }
}
</code></pre>
<p>When I try to run terraform apply I get:</p>
<pre><code>Error: Provider configuration: cannot load Kubernetes client config
invalid configuration: default cluster has no server defined
</code></pre>
<p>The only entry I have in my kubeconfig file is the context for my local kind cluster. What is missing here?</p>
<p>Am I hit by the following github issue?
<a href="https://github.com/hashicorp/terraform/issues/2430" rel="nofollow noreferrer">Provider Issue</a></p>

<p>The <code>kubernetes</code> provider configuration contains an output from the module declared as <code>aks</code>. Prior to version <code>2.4.0</code> of the Kubernetes provider it was possible to simultaneously manage a Kubernetes cluster backing infrastructure and the cluster itself at initial provisioning (or subsequent Delete/Create) by configuring the provider with either resource attributes, or with <code>data</code> attributes. At version <code>2.4.0</code> of the Kubernetes provider, the new experimental Kubernetes provider with the latest Terraform SDK and Kubernetes Go SDK bindings (and consequently Kubernetes API) stabilized and replaced the former Kubernetes provider (ergo why some resources are marked <code>v1</code> and <code>v2</code> as the provider still contained some of the legacy code for backwards support, and only the minor version of the provider was iterated and not the major version according to semantic versioning rules). With this new provider and its use of the modern Kubernetes API it became no longer possible for this simultaneous management at initial provisioning. Therefore the error in the question is observed as Terraform's Kubernetes provider is attempting to configure with a non-existent cluster instead of charting a dependency hierarchy that would imply the provider is dependent upon the <code>aks</code> module.</p>
<p>With all this in mind it becomes clear there are two workarounds. The first is to downgrade the Kubernetes provider to the last version of the old provider:</p>
<pre><code>terraform {
  required_providers {
    kubernetes = {
      source  = &quot;hashicorp/kubernetes&quot;
      version = &quot;&gt;= 2.3.2&quot;
    }
  }
}
</code></pre>
<p>The other solution would be to <a href="https://developer.hashicorp.com/terraform/cli/commands/plan#resource-targeting" rel="nofollow noreferrer"><code>-target</code></a> the <code>aks</code> module first to manually enforce the dependency and populate the outputs, and then subsequently manage the entire Terraform config:</p>
<pre><code>terraform plan -target=module.aks
</code></pre>
