terraform-provider-helm icon indicating copy to clipboard operation
terraform-provider-helm copied to clipboard

Always do `helm repo update`

Open katlimruiz opened this issue 4 years ago • 14 comments

Description

I was trying to install the following manifest:

resource "helm_release" "certmanager" {
  # name of the installation (release)
  name             = "cert-manager"
  repository       = "https://charts.jetstack.io"
  chart            = "cert-manager"
  version          = "1.1.0"
  namespace        = "cert-manager"
  create_namespace = true
  timeout = 120
}

And it did not work. I set SET HELM_DEBUG=1 and it showed me the following error:

Error: no cached repo found. (try 'helm repo update'): open C:\Users\xxx\AppData\Local\Temp\helm\repository\jetstack-index.yaml: The system cannot find the file specified.

I solved it by doing a manual helm repo update in the console, then I ran again tf apply and it worked.

Potential Terraform Configuration

It would be nice to have a new argument so we could decide whether to do a previous helm repo update.

resource "helm_release" "certmanager" {
  # name of the installation (release)
  name             = "cert-manager"
  repository       = "https://charts.jetstack.io"
  chart            = "cert-manager"
  version          = "1.1.0"
  namespace        = "cert-manager"
  create_namespace = true
  timeout = 120
  repo_update = true/false
}

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

katlimruiz avatar Nov 25 '20 19:11 katlimruiz

Could you please share the versions of provider and Terraform that you're using? Also, can you confirm this is happening specifically on Windows?

alexsomesan avatar Dec 02 '20 17:12 alexsomesan

I have the same issues running on Auzre Pipeliens Agents (Ubuntu 20.04) and MacOS (Big Sur 11.1 Beta) locally.

Terraform 0.13.5 Helm 1.3.2

anhdle14 avatar Dec 08 '20 08:12 anhdle14

Terraform v0.14.0

  • provider registry.terraform.io/hashicorp/azurerm v2.39.0
  • provider registry.terraform.io/hashicorp/helm v1.3.2
  • provider registry.terraform.io/hashicorp/kubernetes v1.13.3

Initially I ran the below (identical inputs to OP but in a different order...);

resource "helm_release" "helm_jetstack_cert_manager" {
  name             = "cert-manager"
  namespace        = "cert-manager"
  create_namespace = true
  repository       = "https://charts.jetstack.io"
  chart            = "cert-manager"
  version          = "1.1.0"
  timeout          = 120
}

I received Error: failed to download "https://charts.jetstack.io/charts/cert-manager-v1.1.0.tgz" like https://github.com/rancher/quickstart/issues/141 then by just changing the 'order' of the inputs to match OP I then started getting, no cached repo found. (try 'helm repo update').

I ran helm repo update manually and one of my helm repos failed (my ACR repo failed because I hadn't yet authorised via az acr login), so I removed the XXXXX.azurecr.io helm chart repo and re-ran terraform apply -auto-approve and cert-manager release was then created with no problem - hope that helps someone.

I don't understand how running the same inputs in a different order would cause different error messages!?

f2calv avatar Dec 11 '20 06:12 f2calv

Provider Version: 2.2.0

resource "helm_release" "argo-cd" {
  name                  = "argo-cd"
  repository            = "https://argoproj.github.io/argo-helm"
  chart                 = "argo-cd"
  version               = "3.11.1"
  namespace             = kubernetes_namespace.infra-namespaces["infra-argo-cd"].metadata[0].name
  wait                  = true
  timeout               = 300
  atomic                = true
  cleanup_on_fail       = true
  values                = [""]
}

I could confirm, this error only occurs, if the local helm installation has some contained helm repo

Based on that, I modified the environment variable HELM_REPOSITORY_CONFIG=repositories.yaml

Then, terraform runs successfully.

Could someone confirm that?

Edit: I could resolve the issue, by setting registry_config_path inside

provider "helm" {
  registry_config_path = "repositories.yaml"
  kubernetes {
    ...
  }
}

To the specific value. I could be any value, the file does not need to be exist.

jkroepke avatar Aug 12 '21 09:08 jkroepke

Confirming removing extra repos (helm repo list then helm repo remove <repo>) solved the issue.

j-martin avatar Aug 19 '21 18:08 j-martin

Confirming removing extra repos (helm repo list then helm repo remove <repo>) solved the issue.

You might also need to actually run helm repo update after removing repo. But worked for me, thank you @j-martin.

aram-karapetyan-ada avatar Sep 15 '21 14:09 aram-karapetyan-ada

My workaround for this issue:

provider "helm" {
  repository_config_path = "${path.module}/.helm/repositories.yaml" 
  repository_cache       = "${path.module}/.helm"
  kubernetes {
    host                   = module.cluster_linux.cluster_endpoint
    cluster_ca_certificate = base64decode(module.cluster_linux.cluster_ca[0].data)
    token                  = data.aws_eks_cluster_auth.this.token
  }
}

vasylenko avatar Dec 17 '21 12:12 vasylenko

I notice this issue struck me this time, and the answer is to run "helm repo update" before running helm_release. Previously, I didnt find any problem in my terraform because I deploy some of the resource via helm manually. Then, when I automate everything in terraform - the helm_release complain cannot download the chart *.tgz file. Adding repository_config_path did not help resolve the issue, but running helm repo update resolve the problem.

cakriwut avatar Jul 10 '22 03:07 cakriwut

My workaround for this issue:

provider "helm" {
  repository_config_path = "${path.module}/.helm/repositories.yaml" 
  repository_cache       = "${path.module}/.helm"
  kubernetes {
    host                   = module.cluster_linux.cluster_endpoint
    cluster_ca_certificate = base64decode(module.cluster_linux.cluster_ca[0].data)
    token                  = data.aws_eks_cluster_auth.this.token
  }
}

Im confused about what this is doing. Does it use your local helm cache by default and not run update every time, but if you set it to any other value (even if the folder and repositories.yaml doesn't exist like one poster said) it will update every time?

red8888 avatar Sep 30 '22 20:09 red8888

@red8888, these two strings instruct the provider to look and use the .helm folder in the same directory where you call Terraform, assuming this is your root (aka project directory) TF module and you don't have provider definitions in child modules, of course.

repository_config_path = "${path.module}/.helm/repositories.yaml" 
repository_cache       = "${path.module}/.helm"

https://www.terraform.io/language/expressions/references#filesystem-and-workspace-info

vasylenko avatar Oct 03 '22 12:10 vasylenko

I'm runing the automated pipeline in a remote host, but I'm not able to get a Last version of an helm, I'm instaled the helm 6 months ago, and I need update this chart to lastest version, locally works, but runing on pipeline I got 404 error, on same .tf file but with another target, another state backend, and another runner, repository_config_path and repository_cache doesn't change anything, same 404 error.

felpasl avatar Feb 23 '23 17:02 felpasl

I am currently considering using the unix ticks as the version in the helm chart to make sure it runs. in our pipeline project with checked out values next to repo references, we ALWAYS use helm update -- install ..... This should be an option.
Currently (2.9) this is missing badly because a helm update can decide on its own what needs to be changed.

uvwildos avatar May 06 '23 00:05 uvwildos

Confirming removing extra repos (helm repo list then helm repo remove <repo>) solved the issue.

Confirm this worked for me also. A more elegant solution would be nice, but this quick fix did it for me

KyMidd avatar Feb 05 '24 22:02 KyMidd

Provider Version: 2.2.0

resource "helm_release" "argo-cd" {
  name                  = "argo-cd"
  repository            = "https://argoproj.github.io/argo-helm"
  chart                 = "argo-cd"
  version               = "3.11.1"
  namespace             = kubernetes_namespace.infra-namespaces["infra-argo-cd"].metadata[0].name
  wait                  = true
  timeout               = 300
  atomic                = true
  cleanup_on_fail       = true
  values                = [""]
}

I could confirm, this error only occurs, if the local helm installation has some contained helm repo

Based on that, I modified the environment variable HELM_REPOSITORY_CONFIG=repositories.yaml

Then, terraform runs successfully.

Could someone confirm that?

Edit: I could resolve the issue, by setting registry_config_path inside

provider "helm" {
  registry_config_path = "repositories.yaml"
  kubernetes {
    ...
  }
}

To the specific value. I could be any value, the file does not need to be exist.

export HELM_REPOSITORY_CONFIG=repositories.yaml worked for me. Thanks @jkroepke saved my day.

sivanagireddyb avatar Feb 21 '24 15:02 sivanagireddyb