diff --git a/command/init.go b/command/init.go index b83c7cea9..771b54f93 100644 --- a/command/init.go +++ b/command/init.go @@ -337,6 +337,16 @@ job "example" { # change_signal = "SIGHUP" # } + # The "template" stanza can also be used to create environment variables + # for tasks that prefer those to config files. The task will be restarted + # when data pulled from Consul or Vault changes. + # + # template { + # data = "KEY={{ key \"service/my-key\" }}" + # destination = "local/file.env" + # env = true + # } + # The "vault" stanza instructs the Nomad client to acquire a token from # a HashiCorp Vault server. The Nomad servers must be configured and # authorized to communicate with Vault. By default, Nomad will inject diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 917616ae6..c40a5718e 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -3341,6 +3341,9 @@ func (t *Template) Validate() error { if t.ChangeSignal == "" { multierror.Append(&mErr, fmt.Errorf("Must specify signal value when change mode is signal")) } + if t.Envvars { + multierror.Append(&mErr, fmt.Errorf("cannot use signals with env var templates")) + } default: multierror.Append(&mErr, TemplateChangeModeInvalidError) } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 4dbff3a4a..6562adde2 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -1167,6 +1167,22 @@ func TestTask_Validate_Template(t *testing.T) { if !strings.Contains(err.Error(), "same destination as") { t.Fatalf("err: %s", err) } + + // Env templates can't use signals + task.Templates = []*Template{ + { + Envvars: true, + ChangeMode: "signal", + }, + } + + err = task.Validate(ephemeralDisk) + if err == nil { + t.Fatalf("expected error from Template.Validate") + } + if expected := "cannot use signals"; !strings.Contains(err.Error(), expected) { + t.Errorf("expected to find %q but found %v", expected, err) + } } func TestTemplate_Validate(t *testing.T) {