kubernetesterraformkubernetes-helmistio

How to override default chart values in terraform using helm provider?


We are using helm provider in Terraform to provision istio ingress gateway which in backend use this chart

Below is the terraform code snippet to provision the same. Please help to override the default chart value to create an internal load balancer instead of the default external one. We are aware that it can be done by updating the annotation in the manifest file. But not sure how to do the same in the terraform code snippet?

terraform {
  required_providers {
    helm = {
      source = "hashicorp/helm"
      version = ">= 1.0.0"
    }
  }
}

provider "helm" {
  kubernetes {
    config_path = "${var.kubeconfig_file}"
  }
}

resource "helm_release" "istio-ingress" {
  repository        = local.istio_charts_url
  chart             = "gateway"
  name              = "istio-ingress-gateway"
  namespace         = kubernetes_namespace.istio_system.metadata.0.name
  version           = ">= 1.12.1"
  timeout           = 500
  cleanup_on_fail   = true
  force_update      = false
  depends_on        = [helm_release.istiod]
}

Solution

  • You can either use the set argument block (https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release#set) or the values argument (https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release#values) of the resource helm_release to override the default settings from the original values.yaml

    Should look something like:

    resource "helm_release" "istio-ingress" {
      repository        = local.istio_charts_url
      chart             = "gateway"
      name              = "istio-ingress-gateway"
      namespace         = kubernetes_namespace.istio_system.metadata.0.name
      version           = ">= 1.12.1"
      timeout           = 500
      cleanup_on_fail   = true
      force_update      = false
      depends_on        = [helm_release.istiod]
    
      set {
        name  = "serviceAnnotations.cloud.google.com/load-balancer-type"
        value = "internal"
      }
    }
    

    or

    resource "helm_release" "istio-ingress" {
      repository        = local.istio_charts_url
      chart             = "gateway"
      name              = "istio-ingress-gateway"
      namespace         = kubernetes_namespace.istio_system.metadata.0.name
      version           = ">= 1.12.1"
      timeout           = 500
      cleanup_on_fail   = true
      force_update      = false
      depends_on        = [helm_release.istiod]
    
      values = [
        file("${path.module}/custom-values.yaml")
      ]
    }
    

    and place a custom-values.yaml file in your code.

    This article explains it pretty nicely: https://getbetterdevops.io/terraform-with-helm/

    Hope this helps!