Skip to content

Commit 10e7b8f

Browse files
committed
allow secrets and variables to use valueFrom
Usecase: I have an operator that creates PostgreSQL databases (i.e. CrunchyData PGO, CNPG, etc) and creates a secret with the authentication info. I would like to reference this secret in `TFE_DATABASE_PASSWORD` and `TFE_DATABASE_USER`, but prior to this patch, cannot.
1 parent 961c003 commit 10e7b8f

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

templates/_helpers.tpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,24 @@ Obtains the agent namespace as configured
124124
{{- .Release.Namespace }}-agents
125125
{{- end }}
126126
{{- end }}
127+
128+
{{/*
129+
Prints the key-value pairs from the 'env.secretKeyRefs' and 'env.configMapKeyRefs'
130+
entries as `valueFrom` environment variables in the Values file.
131+
*/}}
132+
{{- define "helpers.list-valueFrom-variables"}}
133+
{{- range $val := .Values.env.secretKeyRefs }}
134+
- name: {{ $val.name }}
135+
valueFrom:
136+
secretKeyRef:
137+
name: {{ $val.secretName }}
138+
key: {{ $val.key }}
139+
{{- end }}
140+
{{- range $val := .Values.env.configMapKeyRefs }}
141+
- name: {{ $val.name }}
142+
valueFrom:
143+
configMapKeyRef:
144+
name: {{ $val.configMapName }}
145+
key: {{ $val.key }}
146+
{{- end }}
147+
{{- end }}

templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ spec:
9999
{{- else }}
100100
{{- toYaml .Values.container.securityContext | nindent 10 }}
101101
{{- end }}
102+
{{- with (include "helpers.list-valueFrom-variables" .) }}
103+
env:
104+
{{- . | indent 10 }}
105+
{{- end }}
102106
envFrom:
103107
- configMapRef:
104108
name: terraform-enterprise-env-config

values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ env:
283283
# TFE_VAULT_ROLE_ID: ""
284284
# TFE_IACT_SUBNETS: ""
285285
# TFE_IACT_TIME_LIMIT: ""
286+
secretKeyRefs:
287+
# - name: SECRET_ENV_VAR
288+
# secretName: my-secret
289+
# key: secret-key
290+
configMapKeyRefs:
291+
# - name: CONFIG_ENV_VAR
292+
# configMapName: my-configmap
293+
# key: config-key
286294

287295
agents:
288296
rbac:

0 commit comments

Comments
 (0)