Helm chart using Terraform helm provider - error executing consecutive charts

1/20/2020

I have to install helm charts using Terraform helm provider. I tried introducing a delay after executing the first as there is a prerequisite to finish installation of the first chart and dependency before the second helm chart is installed. With the below provision script:

resource "helm_release" "istio-init" {
  name       = "istio-init"
  repository = "${data.helm_repository.istio.metadata.0.name}"
  chart      = "istio-init"
  version    = "${var.istio_version}"
  namespace  = "${var.istio_namespace}"
}

resource "null_resource" "delay" {
  provisioner "local-exec" {
    command = "sleep 200"
  }

  depends_on = ["helm_release.istio-init"]
}

resource "helm_release" "istio" {
  name       = "istio"
  repository = "${data.helm_repository.istio.metadata.0.name}"
  chart      = "istio"
  version    = "${var.istio_version}"
  namespace  = "${var.istio_namespace}"
}

I see the "null_resource" delay module runs when the terraform provisioning for the first time. When tried deleting the resources and reran the Terraform script I see the null_resource module never gets executed again and the provisioning errors out. Are Terraform provisioners designed to run only once?

-- Avi
istio
kubernetes-helm
terraform

1 Answer

1/20/2020

Helm has an optional wait flag that actually will block the release until all resources are up. If you specify the wait variable on your helm_release resource, Terraform (and Helm under the hood) will wait for all resources to be up.

For example:

resource "helm_release" "istio-init" {
  name       = "istio-init"
  repository = "${data.helm_repository.istio.metadata.0.name}"
  chart      = "istio-init"
  version    = "${var.istio_version}"
  namespace  = "${var.istio_namespace}"
  wait       = true
  timeout    = 200
}
-- Blokje5
Source: StackOverflow