Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable strict mode during render #393

Closed
shantanugadgil opened this issue Jan 21, 2021 · 2 comments
Closed

enable strict mode during render #393

shantanugadgil opened this issue Jan 21, 2021 · 2 comments

Comments

@shantanugadgil
Copy link
Contributor

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
@angrycub
Copy link
Contributor

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).

@shantanugadgil
Copy link
Contributor Author

shantanugadgil commented Jan 28, 2021

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. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants