0

I have a helm release file test-helm-release.yaml as given below.

apiVersion: helm.toolkit.gitops.io/v2beta1
kind: HelmRelease
metadata:
  name: "test"
  namespace: "test-system"
spec:
  chart:
    spec:
    chart: "test-environment"
    version: "0.1.10"
  values:
    key1: "value1"
    key1: "value1"
    key1: "value1"
    key1: "value1"
    gitRepository:
      url: https://github.com/test-eng/test.git
    helmRepositories:
      - name: testplatform
        url: https://test-platform/charts

While creating the helm release I can pass the values from above helm release to the new release using the below command

   chart=$(yq '.spec.chart.spec.chart' test-helm-release.yaml)
   version=$(yq '.spec.chart.spec.version' test-helm-release.yaml)
   yq '.spec.values' test-helm-release.yaml | helm upgrade --install --values - --version "$version" --namespace test-system --create-namespace test-platform "helm-repo/$chart"

Above code is working perfectly and I'm able to pass the values to the helm release using "yq" command. How I can do the same "yq" function with terraform "helm-release" and git repository data type given below.

   data "github_repository_file" "test-platform" {
     repository = "test-platform"
     branch     = "test"
    file       = "internal/default/test-helm-release.yaml"
   }

 resource "helm_release" "test-platform" {
 name = "test-platform"

 repository       = "https://test-platform/charts"
 chart            = "test-environment"
 namespace        = "test-system"
 create_namespace = true
 timeout          = 800

 lifecycle {
  ignore_changes = all
}
}

Note I cannot use "set" because i want to fetch the values form test-helm-release.yaml dynamically.Any idea how I could fetch the .spec.values alone using templatefile functio or a different way?

mystack
  • 4,910
  • 10
  • 44
  • 75
  • 1
    You can use `set` for that: https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release#set. Or alternatively, you could use the `templatefile` built-in function, but I don't understand where the values should be coming from. – Marko E Jan 10 '23 at 14:39
  • @MarkoE value is coming from the test-helm-release.yaml. in commandline I'm using **"yq '.spec.values' test-helm-release.yaml"** to get it. I cannot use "set" because i want to fetch the values form test-helm-release.yaml dynamically.Any idea how I could fetch the **.spec.values** using templatefile function.? – mystack Jan 10 '23 at 14:54
  • So you don't want to set the value but rather to get it? – Marko E Jan 10 '23 at 15:40
  • @MarkoE yes, it is correct – mystack Jan 10 '23 at 16:04

0 Answers0