Support variables within consul-template (for vault)

1,160 views
Skip to first unread message

Yasin Amadmia

unread,
Jul 27, 2016, 10:18:37 AM7/27/16
to Consul
Hi,
I was wondering if there was way to use variables within consul-templates for vault ?

ex: 

{{ with $my_secret := vault "secret/path/my_secret" }} {{ end }}

I want to use a variable (Shell) instead of path


In Shell: export path=location1
Template: {{ with $my_secret := vault "secret/${path}/my_secret" }} {{ end }}
Template should retrieve from consul path secret/location1/my_secret

Is it possible ?

James Phillips

unread,
Aug 10, 2016, 9:41:35 PM8/10/16
to consu...@googlegroups.com
Hi Yasin,

You should be able to use consul-template's env function for this - https://github.com/hashicorp/consul-template#env. You can use Go template's printf to compose the path from fixed parts and substituting the environment variable from env. Also, you probably don't want to call that environment variable "path" to avoid conflating with "PATH" :-)

-- James

This e-mail and any attachments are confidential and intended solely for the use of the addressee only. If you have received this message in error, you must not copy, distribute or disclose the contents; please notify the sender immediately and delete the message.


This message is attributed to the sender and may not necessarily reflect the view of Travis Perkins Trading Company Limited, 733503, Lodge Way House, Lodge Way, Harlestone Road, Northampton, NN5 7UG or its parent company Travis Perkins plc (Registered in England No. 824821; Lodge Way House, Lodge Way, Harlestone Road, Northampton, NN5 7UG; VAT number 408556737) and any of its subsidiaries. Agreements binding Travis Perkins Trading Company Limited may not be concluded by means of e-mail communication.


E-mail transmissions are not secure and Travis Perkins Trading accepts no responsibility for changes made to this message after it was sent. Whilst steps have been taken to ensure that this message is virus free, Travis Perkins Trading accepts no liability for infection and recommends that you scan this e-mail and any attachments.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/09073dc9-c7fc-4e95-9030-cfdc4341b691%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages