Thank you for your reply. I actually modified this to make it more flexible for our use case.
I changed this to:
vault.hashicorp.com/agent-inject-template-parameters.yml: |
{{ $globalSecret := }}
{{- with secret "kv/default/restricted/service/empty" -}}
{{- with secrets "kv/devops/restricted/service-global" -}}
{{- $globalSecret = .Data.data }}
{{- end }}
db:
database: '{{ index .Data.data "parameters.yml/db.database" }}'
host: test.abcd.com
NRTEST: '{{ index $globalSecret "nr.license" }}'
{{- end }}
I’m hoping to pull secrets from the kv/devops/restricted/service-global path only when $globalSecret is defined.
I think my problem now is defining {{ $globalSecret := }} as a list. If I were to set it as a string like "test", It errors out with
executing "" at <index $globals "nr.license">: error calling index: cannot index slice/array with type string"
I haven’t found information from consul-template documentation to initialize a variable of type list, but I did find that list function is available from sprig library. But it says list is not defined when i try to use it in my template.
I’m hoping that config is a viable solution once we figure out the variable type.