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

add mustEnv function #1657

Merged
merged 1 commit into from
Oct 20, 2022
Merged

Conversation

C-Pro
Copy link
Contributor

@C-Pro C-Pro commented Oct 20, 2022

Background

It is important to fail early and not try to deploy a config with wrong data. But when populating values using env function a typo in variable name will lead to an empty value instead of an error, like when trying to access nonexistent vault key with error_on_missing_key enabled.

This PR addresses it with adding extra mustEnv command that fails if environment variable does not exist or is empty.

$ cat env.tmpl
URL={{mustEnv "ENV"}}:12312

$ ENV=test ~/go/bin/consul-template -once -template=env.tmpl -dry
>
URL=test:12312

$ ~/go/bin/consul-template -once -template=env.tmpl -dry
2022-10-20T18:21:52.794+0700 [ERR] (cli) env.tmpl: execute: template: :1:6: executing "" at <mustEnv "ENV">: error calling mustEnv: required environment variable ENV is empty

@C-Pro C-Pro requested a review from a team October 20, 2022 11:22
@hashicorp-cla
Copy link

hashicorp-cla commented Oct 20, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@eikenb eikenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code, docs, tests... 👍

@eikenb eikenb added this to the v0.30.0 milestone Oct 20, 2022
@eikenb eikenb merged commit 5559838 into hashicorp:main Oct 20, 2022
@eikenb eikenb modified the milestones: v0.30.0, 0.29.6 Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants