gavinbunney / terraform-provider-kubectl

Terraform provider to handle raw kubernetes manifest yaml files
https://registry.terraform.io/providers/gavinbunney/kubectl
Mozilla Public License 2.0
628 stars 108 forks source link

"invalid apiVersion client.authentication.k8s.io/v1" #220

Closed freeone3000 closed 1 year ago

freeone3000 commented 2 years ago

With the following block:

terraform {
    required_version = ">= 1.2.2"
    required_providers {
      kubectl = {
        source  = "gavinbunney/kubectl"
        version = ">= 1.14.0"
      }
  }
}
provider "kubectl" {
  load_config_file       = false
  host                   = data.aws_eks_cluster.eks-cluster.endpoint
  cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks-cluster.certificate_authority[0].data)
  exec {
    api_version = "client.authentication.k8s.io/v1"
    command     = "aws"
    args        = ["eks", "get-token", "--cluster-name", data.aws_eks_cluster.eks-cluster.name]
  }
}

Versions of relevant items:

$ ts --version
2.2.2
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"22+", GitVersion:"v1.22.12-dispatcher-dirty", GitCommit:"fde00375407ad0afadd681a3505054ec83f935ec", GitTreeState:"dirty", BuildDate:"2022-07-19T18:58:44Z", GoVersion:"go1.16.15", Compiler:"gc", Platform:"darwin/arm64"}
Server Version: version.Info{Major:"1", Minor:"22+", GitVersion:"v1.22.13-eks-15b7512", GitCommit:"94138dfbea757d7aaf3b205419578ef186dd5efb", GitTreeState:"clean", BuildDate:"2022-08-31T19:15:48Z", GoVersion:"go1.16.15", Compiler:"gc", Platform:"linux/amd64"}

I get the following error:

╷
│ Error: failed to configure: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1"
│ 
│   with provider["registry.terraform.io/gavinbunney/kubectl"],
│   on provider.tf line 46, in provider "kubectl":
│   46: provider "kubectl" {
│ 
╵

This happened after switching to the exec plugin for kubectl, and I fear there is an incompatibility with this cluster version and this kubectl version. Is there any advice on fixing this issue?

zeppelinen commented 2 years ago

For kubectl > 1.24 or aws-cli > 2.7.0 you should use api_version = "client.authentication.k8s.io/v1beta1"

jayanath commented 2 years ago

This works with EKS - Kubernetes 1.23

provider "kubectl" {
  host                   = data.terraform_remote_state.eks.outputs.cluster_endpoint
  cluster_ca_certificate = base64decode(data.terraform_remote_state.eks.outputs.cluster_certificate_authority_data)
  load_config_file       = false
  exec {
    api_version = "client.authentication.k8s.io/v1beta1"
    args        = ["eks", "get-token", "--cluster-name", "${data.terraform_remote_state.eks.outputs.cluster_id}"]
    command     = "aws"
  }
}
omerfsen commented 1 year ago

I had the same error. v1.24.8-eks-ffeb93d

will use

    api_version = "client.authentication.k8s.io/v1beta1"

to solve this isssue.