The answers here weren't quite enough for me, so I took them as a baseline and improved them until I had something that worked.
I still wanted the recursive reading of any properties under some sort of key in my values.yaml, but I wanted it to be formatted for use with dotenv.
Here's what I came up with:
values.yaml
config:
database:
name: my-db
host: my-db-host
port: 5432
ConfigMap
data:
.env: |-
{{- include "envify" (list "" .Values.config . ) | nindent 4 }}
Template:
{{- define "envify" -}}
{{- $prefix := index . 0 -}}
{{- $value := index . 1 -}}
{{- if kindIs "map" $value -}}
{{- range $k, $v := $value -}}
{{- if $prefix -}}
{{- template "envify" (list (printf "%s_%s" $prefix $k | upper) $v) -}}
{{- else -}}
{{- template "envify" (list (printf "%s" $k) $v) -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{ $prefix }}={{ $value }}
{{ end -}}
{{- end -}}
Output:
data:
.env: |-
DATABASE_NAME=my-db
DATABASE_HOST=my-db-host
DATABASE_PORT=5432
Hopefully this helps someone.