terraform kubectl provider not found

10/20/2020

I'm trying to add kubectl provider for terraform module and I follow the docs from Terraform kubectl. I run terraform init and provider is installed with success but when I try to add a sample config, for ex: ( or thers from here )

resource "kubectl_server_version" "current" {}

and run terraform plan I got the following msg:

Error: Could not load plugin
Failed to instantiate provider "registry.terraform.io/hashicorp/kubectl" to
obtain schema: unknown provider "registry.terraform.io/hashicorp/kubectl"

and when I tun terraform init ( with the resource in place in module k8s )

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

some outputs:

$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
  ....

some config files:

terraform.tf

terraform {

  required_version  = "0.13.4"

  backend "gcs" {
    ...
  }

  required_providers {
    kubernetes = {
        source        = "hashicorp/kubernetes"
        version       = "1.13.2"
      }

    kubectl = {
      source          = "gavinbunney/kubectl"
      version         = "1.9.1"
    }
....

terraform successfully init the gavinbunney/kubectl provider but when I add resource "kubectl_manifest" ... in k8s.module terraform is trying to load hashicorp/kubectl provider

what i'm missing? :)

-- Padi
kubectl
kubernetes
terraform
terraform-provider-gcp

5 Answers

5/2/2021

It seems that if you leave only the kubernetes provider, the kubectl provider works just fine. Means, no need to declare kubernetes and kubectl providers.

-- Sergey Korolev
Source: StackOverflow

5/14/2021

In my case it was due to referencing kubectl resources in a module, but the module needed the provider adding to required_providers within the module:

terraform {
  required_providers {
    kubectl = {
      source  = "gavinbunney/kubectl"
      version = "x.x.x"
    }
  }
}
-- Jethro
Source: StackOverflow

10/21/2020

Seems like the problem was that I had the resource "kubectl_server_version" "current" {} among with other resources from hashicorp/kubernetes resources in same module and terraform was trying to load kubectl from hashicorp/kubectl.

When I added gavinbunney/kubectl's resources in main.tf all works good :)

-- Padi
Source: StackOverflow

10/21/2020

When I read the file cat .terraform/plugins/selections.json, I hunderstand that the package is not realy well installed.

In my project, I did :

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

and after:

terraform init

This look to resolve the problem.

-- ARMP125
Source: StackOverflow

11/2/2020

To resolve this issue you can look into terraform state replace-provider registry.terraform.io/hashicorp/kubectl gavinbunney/kubectl

-- RVndra Singh
Source: StackOverflow