Problems with terraform init and 3 party kubectl_manifest module

I’m attempting to perform terraform init with modules using the kubectl_manifest, this is what I get:

Initializing provider plugins...
- Finding latest version of hashicorp/kubectl...
- Reusing previous version of hashicorp/azuread from the dependency lock file
- Reusing previous version of hashicorp/kubernetes from the dependency lock file
- Reusing previous version of hashicorp/helm from the dependency lock file
- Reusing previous version of hashicorp/null from the dependency lock file
- Reusing previous version of hashicorp/local from the dependency lock file
- Reusing previous version of hashicorp/azurerm from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Finding gavinbunney/kubectl versions matching "1.9.1"...
- Using previously-installed hashicorp/azurerm v2.48.0
- Using previously-installed hashicorp/random v3.1.0
- Installing gavinbunney/kubectl v1.9.1...
- Installed gavinbunney/kubectl v1.9.1 (self-signed, key ID AD64217B5ADD572F)
- Using previously-installed hashicorp/azuread v1.4.0
- Using previously-installed hashicorp/kubernetes v2.0.2
- Using previously-installed hashicorp/helm v2.0.2
- Using previously-installed hashicorp/null v3.1.0
- Using previously-installed hashicorp/local v2.1.0

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider
hashicorp/kubectl: provider registry registry.terraform.io does not have a
provider named registry.terraform.io/hashicorp/kubectl

If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.

I’ve seen advice on another thread on this forum suggesting that using a terraform block that looks like this might resolve the issue:

terraform {
  required_providers {
    kubectl = {
      source          = "gavinbunney/kubectl"
      version         = "1.9.1"
    }
  }
}

I’ve tried this and its made no difference, I get the exact same error as before. I have also seen people recommend the following:

cp -R .terraform/plugins/registry.terraform.io/gavinbunney/kubectl .terraform/plugins/registry.terraform.io/hashicorp

This does not work for me either as I have no .plugins directory under any of my .terraform directories.

Any guidance / help in resolving this would be much appreciated.

This is what I am using and it worked for me.

kubectl = {
  source = "cpanato/kubectl"
  version = "1.14.1"
}

I didn’t see this message the first time around, but FWIW if you see an error like this then it suggests that somewhere in your configuration there is a module referring to the short name “kubectl” without including a required_providers block to specify which provider that short name is representing.

Each module has its own namespace of provider local names, and so each module that refers to “kubectl” must have its own required_providers block specifying which provider that local name is referring to.

To allow still using modules that were written for now-very-old versions of Terraform, before there was more than one namespace of providers, Terraform guesses that any undeclared provider is intended to be in the hashicorp/ namespace, but that’s an incorrect guess in this case because there is no such provider as hashicorp/kubectl.

If you don’t already know which module is the one with the missing required_providers entry, one way to find out is to run the terraform providers command. That will list the providers that each module depends on, and so one of them will presumably show as requiring hashicorp/kubectl and that is the one that is missing its required_providers entry.