terraform How to pass a file as value for helm_release to create config map

5/6/2021

I have a helm chart that is creating a config map for which I am passing content as a value from terraform using helm_release.

values.yml: default is empty

sql_queries_file: ""

helm template for configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: sql-queries
data:
{{ .Values.sql_queries_file }}

terraform file:

resource "helm_release" "example" {
............
..................
  set {
    name  = "sql_queries_file"
    value = file(./sql_queries.sql)
  }
}

I have a sql_queris.sql fine inside terraform folder with sample data below.

-- From http://docs.confluent.io/current/ksql/docs/tutorials/basics-docker.html#create-a-stream-and-table

-- Create a stream pageviews_original from the Kafka topic pageviews, specifying the value_format of DELIMITED
CREATE STREAM pageviews_original (viewtime bigint, userid varchar, pageid varchar) WITH (kafka_topic='pageviews', value_format='DELIMITED');

Error:

Failed parsing key sql_queries_file with value <entire content here>

Is this the right way? or is there a better way?

-- SNR
kubernetes
kubernetes-helm
terraform

1 Answer

5/6/2021

I would use filebase64 to get the file with terraform to avoid templating issues. You can unmarshal it in helm like this: {{ b64dec .Values.sql_queries_file }}. By the way you should use data field in configMaps like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: sql-queries
data: 
  sql_queries.sql: |-
    {{ .Values.sql_queries_file | nindent 4 }}
#   {{ b64dec .Values.sql_queries_file | nindent 4 }} if you want to unmarshal

Edit: fixed typo in answer.

-- Akin Ozer
Source: StackOverflow