How do I pass variables to a yaml file in helm.tf?

13k views Asked by At

I have a file for creating terraform resources with helm helm.tf.

In this file I create a honeycomb agent and need to pass in some watchers, so I'm using a yaml file for configuration. Here is the snippet from helm.tf:

resource "helm_release" "honeycomb" {
  version = "0.11.0"
  depends_on = [module.eks]
  repository = "https://honeycombio.github.io/helm-charts"
  chart = "honeycomb"
  name = "honeycomb"

  values = [
    file("modules/kubernetes/helm/honeycomb.yml")
  ]
}

and here is the yaml file

agent:
  watchers:
    - labelSelector: "app=my-app"
      namespace: my-namespace
      dataset: {{$env}}
      parser:
        name: nginx
        dataset: {{$env}}
        options:
          log_format: "blah"

Unfortunately my attempt at setting the variables with {{$x}} has not worked, so how would I send the env variable to the yaml values file? I have the variable available to me in the tf file but am unsure how to set it up in the values file.

Thanks

1

There are 1 answers

1
rajesh-nitc On BEST ANSWER

You may use templatefile function

main.tf

resource "helm_release" "honeycomb" {
  version    = "0.11.0"
  depends_on = [module.eks]
  repository = "https://honeycombio.github.io/helm-charts"
  chart      = "honeycomb"
  name       = "honeycomb"

  values = [
    templatefile("modules/kubernetes/helm/honeycomb.yml", { env = "${var.env}" })
  ]
}

honeycomb.yml

agent:
  watchers:
    - labelSelector: "app=my-app"
      namespace: my-namespace
      dataset: "${env}"
      parser:
        name: nginx
        dataset: "${env}"
        options:
          log_format: "blah"