hashicorp / terraform-provider-helm

Terraform Helm provider
https://www.terraform.io/docs/providers/helm/
Mozilla Public License 2.0
992 stars 364 forks source link

Always do `helm repo update` #630

Open katlimruiz opened 3 years ago

katlimruiz commented 3 years ago

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

alexsomesan commented 3 years ago

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

anhdle14 commented 3 years ago

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

f2calv commented 3 years ago

Terraform v0.14.0

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!?

jkroepke commented 2 years ago

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.

j-martin commented 2 years ago

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

aram-karapetyan-ada commented 2 years ago

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.

vasylenko commented 2 years ago

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
  }
}
cakriwut commented 2 years ago

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.

red8888 commented 1 year ago

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?

vasylenko commented 1 year ago

@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

felpasl commented 1 year ago

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.

uvwildos commented 1 year ago

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.

KyMidd commented 5 months ago

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

sivanagireddyb commented 5 months ago

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.