<p>I'm trying to add kubectl provider for terraform module and I follow the docs from <a href="https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs" rel="nofollow noreferrer">Terraform kubectl</a>. I run <code>terraform init</code> and provider is installed with success but when I try to add a sample config, for ex: ( or thers from <a href="https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/kubectl_manifest" rel="nofollow noreferrer">here</a> )</p>
<pre><code>resource &quot;kubectl_server_version&quot; &quot;current&quot; {}
</code></pre>
<p>and run <code>terraform plan</code> I got the following msg:</p>
<pre><code>Error: Could not load plugin
Failed to instantiate provider &quot;registry.terraform.io/hashicorp/kubectl&quot; to
obtain schema: unknown provider &quot;registry.terraform.io/hashicorp/kubectl&quot;
</code></pre>
<p>and when I tun <code>terraform init</code> ( with the resource in place in module k8s )</p>
<pre><code>Error: Failed to install provider

Error while installing hashicorp/kubectl: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/kubectl
</code></pre>
<p>some outputs:</p>
<pre><code>$terraform plugins

├── provider[registry.terraform.io/hashicorp/kubernetes] 1.13.2
├── provider[registry.terraform.io/gavinbunney/kubectl] 1.9.1
├── module.k8s
│   ├── provider[registry.terraform.io/hashicorp/kubectl]
│   └── provider[registry.terraform.io/hashicorp/kubernetes]



$terraform init

Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Using previously-installed hashicorp/kubernetes v1.13.2
- Using previously-installed gavinbunney/kubectl v1.9.1

$terraform -v

Terraform v0.13.4
  + provider registry.terraform.io/gavinbunney/kubectl v1.9.1
  + provider registry.terraform.io/hashicorp/kubernetes v1.13.2
  ....
</code></pre>
<p>some config files:</p>
<p>terraform.tf</p>
<pre><code>terraform {

  required_version  = &quot;0.13.4&quot;

  backend &quot;gcs&quot; {
    ...
  }

  required_providers {
    kubernetes = {
        source        = &quot;hashicorp/kubernetes&quot;
        version       = &quot;1.13.2&quot;
      }

    kubectl = {
      source          = &quot;gavinbunney/kubectl&quot;
      version         = &quot;1.9.1&quot;
    }
....
</code></pre>
<p>terraform successfully init the <code>gavinbunney/kubectl</code> provider but when I add <code>resource &quot;kubectl_manifest&quot; ...</code> in k8s.module terraform is trying to load <code>hashicorp/kubectl</code> provider</p>
<p>what i'm missing? :)</p>
<p><strong>Update</strong>
with terraform 1.4.0</p>
<pre><code>required_providers {
    kubernetes = {
      source = &quot;hashicorp/kubernetes&quot;
      version = &quot;2.18.1&quot;
    }
  }

provider &quot;kubernetes&quot; {
  host                   = module.k8s.cluster_endpoint
  cluster_ca_certificate = base64decode(module.k8s.cluster_certificate_authority_data)

  exec {
    api_version = &quot;client.authentication.k8s.io/v1beta1&quot;
    command     = &quot;aws&quot;
    args        = [&quot;eks&quot;, &quot;get-token&quot;, &quot;--cluster-name&quot;, module.k8s.cluster_name]
  }
}

resource &quot;kubernetes_namespace&quot; &quot;velero&quot; {
  metadata {
    name = var.velero_ns
  }
}
</code></pre>

<p>In my case it was due to referencing kubectl resources in a module, but the module needed the provider adding to <code>required_providers</code> within the module:</p>
<pre><code>terraform {
  required_providers {
    kubectl = {
      source  = &quot;gavinbunney/kubectl&quot;
      version = &quot;x.x.x&quot;
    }
  }
}

</code></pre>
