hashicorp / levant

An open source templating and deployment tool for HashiCorp Nomad jobs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

enable strict mode during render

shantanugadgil opened this issue · comments

add option for strict mode during render
If/when a variable is not defined during rendering, cause the render to fail with non-zero rather than continue.

Relevant Nomad job specification file

$ cat curdate.tpl 
[[ .curdate ]]
[[ .something ]]
[[ .anything ]]

$ cat curdate.default.json 
{
        "something": "foo",
        "anything": "bar"
}

Output of levant version:

Levant v0.3.0-beta1 (bb0922f6)


$ levant render  -var-file curdate.default.json -var "curdate1=$(date +'%Y-%m-%d')" curdate.tpl 
2021-01-21T07:29:25-08:00 |INFO| helper/variable: using command line variable with key curdate1 and value 2021-01-21
2021-01-21T07:29:25-08:00 |INFO| helper/variable: using variable with key something and value foo from file
2021-01-21T07:29:25-08:00 |INFO| helper/variable: using variable with key anything and value bar from file
<no value>
foo
bar

$ echo $?
0

notice purposeful typo of input variable curdate

Output of consul version:

n/a

Output of nomad version:

n/a

You can currently create strict behavior in 0.3.0-beta by testing the variable and using the Sprig fail function. However, there is some art on making this an all-or-nothing option at the command line too (#308).

Bingo. I can use fail for a few variables, but becomes unwieldy soon.
I didn't know the PR #308 existed, but I second that entirely!!!
In fact I would favor strict as the default (with an option of no-strict or relaxed, but curious why would anyone explicitly want relaxed mode?)

EDIT: My only real requirement was a non-zero return to be able to bail from some automation scripts. Any specific error messages would be obviously helpful. 😁