hashicorp/levant

Add replace function to template

Closed this issue · 2 comments

Description

Since there is no way to include "_" in job names and to use interpolated variables from nomad "-" in job names are replaced by "_" it would be useful to have a replace function.

Relevant Nomad job specification file

For template stanza it would be easy to use replaceAll from consul-template. For config stanza, not so much.

Output of levant version:

Levant v0.2.7
Date: 2019-03-19T08:26:24Z
Commit: 9e952d55f171e63f5c7955e826401eac91ed0b28
Branch: 0.2.7
State: 0.2.7
Summary: 9e952d55f171e63f5c7955e826401eac91ed0b28

Output of consul version:

Consul v1.5.1
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

Output of nomad version:

Nomad v0.9.3 (c5e8b66c3789e4e7f9a83b4e188e9a937eea43ce)

Additional environment details:

thanks for the request @rafaelpirolla; so would the replace function perform something similar to this?

template:

[[ replace "-" "replace_underscore_with_dash" ]]

render:

"replace-underscore-with-dash"

We could make it a general solution as we have the opportunity:
[[ replace "Batman and Robin" "Robin" "Catwoman" ]]

But yes my use case would be:
[[ replace .job.name "-" "_" ]]