-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
template: error on missing key #14002
Conversation
- `error_on_missing_key` `(bool: false)` - Specifies how the template behaves | ||
when attempting to index a struct or map key that does not exist. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be good to expand on what happens for each value, as the naming can be a bit misleading. Something like this perhaps (not sure if I got it right 😅):
If set to
true
the task will fail if a template tries to access a key that doesn't in a map , iffalse
an empty value will be used in the template instead.
command/agent/job_endpoint_test.go
Outdated
@@ -2742,6 +2743,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) { | |||
Min: helper.TimeToPtr(5 * time.Second), | |||
Max: helper.TimeToPtr(10 * time.Second), | |||
}, | |||
ErrMissingKey: pointer.Of[bool](true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause the backport to fail like in the other PR. Since all the other tests use the helper
package already it may be good to avoid pointer
here for now to get a clean merge and save some manual work.
Thank you for working on this, @DerekStrickland! I've been bitten by this issue. Do you plan on working on this? If not, I can pick this up. |
Co-authored-by: Luiz Aoqui <luiz@hashicorp.com> Co-authored-by: Derek Strickland <1111455+DerekStrickland@users.noreply.github.com>
Hi @rodrigol-chan 👋 Could you explain the scenario you had where this would be useful? We paused work on this because this |
I'm using the Vault integration to template some secrets into a file. Unfortunately, I forgot to add all of the key-value pairs and instead of a nice Nomad error telling me a key-value pair does not exist, I had to figure out that As I understand it, if the whole secret does not exist, it already fails to launch the task. But if a key in the secret does not exist, it's silently templated as the wrong value. |
Closing in favor of #15141 |
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
This PR adds the consul-template configuration option
error_on_missing_key
. This allows jobspec authors to specify that a template should fail if it references a struct or map key that does not exist. The default value isfalse
and should be fully backward compatible.