Helm indentation in values file

226 Views Asked by At

I am deploying the official airflow helm chart https://artifacthub.io/packages/helm/apache-airflow/airflow using terraform and I am trying to read a pod template file using the file function and use it inside the values.yaml

resource "helm_release" "airflow" {
  name       = "airflow"
  namespace  = "airflow"
  repository = "https://airflow.apache.org"
  chart      = "airflow"
  version    = "1.11.0"

  values = [
    templatefile("values.yaml", {
      ...
      template_file = file("${path.module}/airflow_templates/common_template.yaml")
    })
  ]
}

My main focus is on the extraConfigMaps from https://github.com/apache/airflow/blob/main/chart/values.yaml#L349

extraConfigMaps:
  airflow-pod-templates-cm:
    data: |-
      test: 'hello'
      common_template.yaml: "${template_file}" 

however this gives me

Error: ---> error converting YAML to JSON: yaml: line 109: could not find expected ':'

which I suspect is the wrong indentation, because the content of common_template.yaml is printed correctly. I am unable to set the correct indentation though, I tried various versions of templating like {{ printf "${template_path}" | indent 8 }} or {{ "${template_path}" | indent 8 }} , but can't get it to work properly. How do I indent this correctly?

Content of the common_template.yaml is this file https://github.com/apache/airflow/blob/main/chart/files/pod-template-file.kubernetes-helm-yaml

2

There are 2 best solutions below

0
On BEST ANSWER

Eventually solved it using in the tf file

template_file = indent(8, file("${path.module}/airflow_templates/common_template.yaml"))

and in the values file

extraConfigMaps:
  airflow-pod-templates-cm:
    data: |
      common_template.yaml: |-
        ${template_path}
2
On

I think you've - after | for "data", can you try following instead

extraConfigMaps:
  airflow-pod-templates-cm:
    data: |
      test: 'hello'
      common_template.yaml: "${template_file}"