terraform-provider-helm: Error: stat /Users/xxxxx/.kube/config: no such file or directory when trying to use with EKS

Terraform Version

12.18

Affected Resource(s)

  • helm_release

Terraform Configuration Files

data "aws_eks_cluster_auth" "cluster-auth" {
  depends_on = [aws_eks_cluster.default]
  name       = "aws_eks_cluster.default"
}

provider "helm" {
  alias = "eks"
  kubernetes {
    # config_path = "${path.module}/.kube/config"
    host                   = aws_eks_cluster.default.endpoint
    cluster_ca_certificate = aws_eks_cluster.default.certificate_authority[0].data #base64decode(aws_eks_cluster.default.certificate_authority.0.data)
    token                  = data.aws_eks_cluster_auth.cluster-auth.token
    load_config_file       = false
  }
}

resource "helm_release" "controllers" {
  name  = "controllers"
  atomic = true
  chart = "./controllers"
  depends_on = [
    aws_eks_cluster.default,
    local_file.kubeconfig,
    aws_autoscaling_group.default
  ]

  set {
    name  = "clusterName"
    value = aws_eks_cluster.default.id
  }

  set {
    name  = "region"
    value = var.aws_region
  }

  set {
    name  = "zone"
    value = var.route53zone

Expected Behavior

It creates a Helm release with my the YAML in my controllers folder.

Actual Behavior

Receive this errors instead:

_Error: stat /Users/xxxxx/.kube/config: no such file or directory

on main.tf line 610, in resource “helm_release” “controllers”: 610: resource “helm_release” “controllers” {_

Here’s what I know; if I have a ~/.kube/config file present, everything works just fine. Thus, when running terraform apply locally on my laptop, it works. However, I’m trying to replicate running terraform apply in a fresh container in our CD platform, which won’t have that file.

Now, oddly enough, even though the rest of my EKS TF module has commands all over the place using “${path.module}/.kube/config” as the source for the kubeconfig and work just fine, Helm3 provider does not. It INSISTS I have a config file at ~/.kube/config, even though I:

  1. Have a perfectly useable one at ${path.module}/.kube/config, path.module being the root of my module repo. This is useable with literally everything else, including various kubectl commands.
  2. Tried, as you can see above, not even using a file and just configuring the provider with the cert, token, etc., as well as specifying load_config_file to false. The provider seems to not care about any of this, everything be damned if there is no ~/.kube.config.

Steps to Reproduce

terraform apply against an EKS cluster.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

I use another way: Output from my eks modules:

data "aws_eks_cluster" "cluster" {
  name = module.eks.cluster_id
}

data "aws_eks_cluster_auth" "cluster" {
  name = module.eks.cluster_id
}

output "cluster_certificate" {
  description = "Certificate for EKS control plane."
  value       = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
}

output "cluster_endpoint" {
  description = "Endpoint for EKS control plane."
  value       = module.eks.cluster_endpoint
}

output "cluster_token" {
  description = "Token for EKS control plane."
  value       = data.aws_eks_cluster_auth.cluster.token
}

here is my main modules call:

module "k8s-cluster" {
  source                  = "./modules/k8s-cluster"
  ...
}

module "nginx-ingress-controller" {
  source              = "./modules/nginx-ingress-controller"
  cluster_name        = var.cluster_name
  dns_zone_name       = var.dns_zone_name
  cluster_certificate = module.k8s-cluster.cluster_certificate
  cluster_endpoint    = module.k8s-cluster.cluster_endpoint
  cluster_token       = module.k8s-cluster.cluster_token
}

Get it in my next modules with:

provider "helm" {
  version = "~> 1.1.1"
  kubernetes {
    load_config_file       = false
    host                   = var.cluster_endpoint
    cluster_ca_certificate = var.cluster_certificate
    token                  = var.cluster_token
  }
}