0

I have the following code block in my Helm chart (deployment.yml)

{{`{{- with secret "my/path/kv/key" }}
{{ .Data.data.key | indent 10 }}
{{- end }} `}}

I would like to replace the second line {{ .Data.data.key | indent 10 }} with a variable from Values file.

For instance, instead of having .Data.data.key hardcoded, I would like to have a variable, which can take for instance

{{ .Data.data.key | indent 10 }}
{{ .Data.key | indent 10 }}
{{ .Data.data.mykey | indent 10 }}
etc

I went to add this to my Values file:

vault:
  data_path: .Data.data.key
vault:
  data_path: .Data.key
vault:
  data_path: .Data.data.mykey

And this to my deployment file:

{{`{{- with secret "my/path/kv/key" }}
{{ {{ .Values.vault.data_path }} | indent 10 }}
{{- end }} `}}

I was hoping this would evaluate and take the value from the Values file.

However, it is not working.

The result would be just:

{{`{{- with secret "my/path/kv/key" }}
{{ {{ .Values.vault.data_path }} | indent 10 }}
{{- end }} `}}

Instead of

{{`{{- with secret "my/path/kv/key" }}
{{ .Data.data.key | indent 10 }}
{{- end }} `}}

What is the correct syntax to evaluate the second line?

1 Answer 1

1

The output of your template is Go text/template code. It looks like your problem is really that you're inside a backtick-quoted string

{{`arbitrary text including {{ ... }} expressions that's not interpreted`}}

and you need to evaluate some expression there. That is, if I'm reading the question correctly, you need the values-file string to appear in the output, but not itself be quoted, and not evaluated directly by Helm.

One way is to move the backticks around, so that the expression you're trying to evaluate is outside the quoted string. This potentially looks like

{{`{{- with secret "my/path/kv/key" }}
{{ `}}{{ .Values.vault.data_path }}{{` | indent 10 }}
{{- end }} `}}

Note the extra punctuation in the second line in the second line: we exit the quoted string and the first template expression, we include the expression you want to evaluate, and then we start a third template expression again beginning with a backtick.

It's a style change, but I also might write this only quoting the double-open-curly-braces; you may or may not find it easier to read.

{{ "{{" }}- with secret "my/path/kv/key" }}
{{ "{{" }} {{ .Values.vault.data_path }} | indent 10 }}
{{ "{{" }}- end }}

Now most of the text isn't inside a backtick-quoted string so you don't need extra syntax right around the expression you're evaluating, but the syntax for writing a literal {{ out is longer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.