Skip to content

Commit

Permalink
fix environment file loading in env config map (hashicorp#24)
Browse files Browse the repository at this point in the history
* read env file contents and add it to config map
  • Loading branch information
miguelhrocha authored Jul 7, 2023
1 parent a74940f commit ad8cb01
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
25 changes: 23 additions & 2 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,35 @@ Create the name of the service account to use
{{- end }}
{{- end }}

{{/*
Prints the key-value pair from the 'env.variables' entry in the Values file.
*/}}
{{- define "helpers.list-env-variables"}}
{{- range $key, $val := .Values.env.variables }}
"{{ $key }}": "${{ $val }}"
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end }}

{{/*
Prints the key-value pair from the 'env.secrets' entry in the Values file
and base64 encodes the value.
*/}}
{{- define "helpers.list-env-secrets" }}
{{- range $key, $val := .Values.env.secrets }}
"{{ $key }}": "${{ $val }}"
{{ $key }}: {{ $val | b64enc }}
{{- end }}
{{- end }}

{{/*
Prints the file contents of the environment secrets file
and base64 encodes the value from the key-value pair.
*/}}
{{- define "helpers.enc-b64-secrets-file" }}
{{- range .Files.Lines .Values.env.secretsFilePath }}
{{- $kv := splitList ":" . -}}
{{- $k := first $kv -}}
{{- if and ($k) (eq (hasPrefix "#" $k) false) }}
{{ $k }}: {{ last $kv | b64enc }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion templates/config-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ data:
{{- if .Values.tls.caCertData }}
TFE_TLS_CA_BUNDLE_FILE: {{ include "cacert.path" . }}
{{- end }}
{{ (.Files.Glob .Values.env.configFilePath).AsConfig | indent 2 }}
{{- if .Values.env.configFilePath }}
{{ .Files.Get .Values.env.configFilePath | indent 2 }}
{{- end }}
4 changes: 3 additions & 1 deletion templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ metadata:
namespace: {{ .Release.Namespace }}
data:
{{- include "helpers.list-env-secrets" . | indent 2 }}
{{ (.Files.Glob .Values.env.secretsFilePath ).AsSecrets | indent 2 }}
{{- if .Values.env.secretsFilePath }}
{{- include "helpers.enc-b64-secrets-file" . | indent 2 }}
{{- end }}

3 changes: 1 addition & 2 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ env:
# TFE_OBJECT_STORAGE_S3_SECRET_ACCESS_KEY: ""
# TFE_VAULT_SECRET_ID: ""
variables: {}
# TFE_OPERATIONAL_MODE: external
# TFE_CAPACITY_CONCURRENCY: ""
# TFE_CAPACITY_CPU: ""
# TFE_CAPACITY_MEMORY: ""
Expand Down Expand Up @@ -188,8 +189,6 @@ env:
# TFE_VAULT_ROLE_ID: ""
configMapRefs: []
# - name:
# filepath:
secretRefs: []
# - name:
# filepath:

0 comments on commit ad8cb01

Please sign in to comment.