terraformairflowkubernetes-helmterraform-provider-helm

Helm indentation in values file


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


Solution

  • 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}