From 8b2067ecf634dfe284b6a7ebc683582947fb6215 Mon Sep 17 00:00:00 2001 From: Patrick Hemmer Date: Thu, 29 Oct 2020 12:42:26 -0400 Subject: [PATCH] add template-error-fatal --- README.md | 9 +++++++++ cli.go | 16 +++++++++++++++- config/config.go | 19 +++++++++++++++++++ config/template.go | 16 ++++++++++++++++ config/template_test.go | 1 + manager/runner.go | 39 +++++++++++++++++++++++++++++++++------ template/template.go | 14 ++++++++++++++ 7 files changed, 107 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5f34ed522..d65efbe88 100644 --- a/README.md +++ b/README.md @@ -374,6 +374,11 @@ log_level = "warn" # to the process. pid_file = "/path/to/pid" +# This controls whether an error within a template will cause consul-template +# to immediately exit. This value can be overridden within each template +# configuration. +template_error_fatal = true + # This is the quiescence timers; it defines the minimum and maximum amount of # time to wait for the cluster to reach a consistent state before rendering a # template. This is useful to enable in systems that have a lot of flapping, @@ -585,6 +590,10 @@ template { # retrieving secrets from Vault. error_on_missing_key = false + # This controls whether an error within the template will cause + # consul-template to immediately exit. + error_fatal = true + # This is the permission to render the file. If this option is left # unspecified, Consul Template will attempt to match the permissions of the # file that already exists at the destination path. If no file exists at that diff --git a/cli.go b/cli.go index f038ff118..00a8f67d1 100644 --- a/cli.go +++ b/cli.go @@ -433,6 +433,11 @@ func (cli *CLI) ParseFlags(args []string) ( return nil }), "template", "") + flags.Var((funcBoolVar)(func(b bool) error { + c.TemplateErrFatal = config.Bool(b) + return nil + }), "template-error-fatal", "") + flags.Var((funcVar)(func(s string) error { c.Vault.Address = config.String(s) return nil @@ -581,6 +586,11 @@ func loadConfigs(paths []string, o *config.Config) (*config.Config, error) { } finalC = finalC.Merge(o) + if o.TemplateErrFatal != nil { + for _, tmpl := range *finalC.Templates { + tmpl.ErrFatal = o.TemplateErrFatal + } + } finalC.Finalize() return finalC, nil } @@ -746,7 +756,11 @@ Options: attribute is supplied, the -syslog flag must also be supplied -template=