hashicorp/nomad · error
A template must be supplied using '-template' when using go-
Error message
A template must be supplied using '-template' when using go-template formatting
What it means
VarGetCommand.validateOutputFlag requires -template when -output=go-template, because go-template rendering has nothing to render without one. This error is returned before any server request is made.
Source
Thrown at command/var_get.go:210
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Warn(hint)
}
return 0
}
func (c *VarGetCommand) validateOutputFlag() error {
if c.outFmt != "go-template" && c.tmpl != "" {
return errors.New(errUnexpectedTemplate)
}
switch c.outFmt {
case "hcl", "json", "none", "table":
return nil
case "go-template": //noop - needs more validation
if c.tmpl == "" {
return errors.New(errMissingTemplate)
}
return nil
default:
return errors.New(errInvalidOutFormat)
}
}
func (c *VarGetCommand) GetConcurrentUI() cli.ConcurrentUi {
return cli.ConcurrentUi{Ui: c.Ui}
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Add a -template flag with a valid Go template, e.g. -template='{{ .Data.data }}'
- Or switch -output to a format that needs no template (table, json, hcl, none)
Example fix
// before
vault kv get -output=go-template secret/foo
// after
vault kv get -output=go-template -template='{{ .Data.data.foo }}' secret/foo Defensive patterns
Strategy: validation
Validate before calling
if outFmt == "go-template" && tmpl == "" {
return errors.New("-output=go-template requires -template")
} Try / catch
if err := cmd.validateOutputFlag(); err != nil {
if strings.Contains(err.Error(), "template must be supplied") {
// prompt user for -template or fall back to table output
}
return err
} Prevention
- When setting -output=go-template, always pair it with -template in the same command/profile
- Default to table output in scripts to avoid template requirements
- Keep go-template invocations in wrapper functions that enforce the template argument
When it happens
Trigger: Running `vault kv get -output=go-template <path>` without supplying -template (c.outFmt == "go-template" and c.tmpl == "").
Common situations: Setting the output format in config or a script but forgetting the template argument; aliasing `vault kv get -o go-template` assuming a default template exists.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- The '-template' flag is only valid when using 'go-template'
- Invalid value for "-out"; valid values are [go-template, hcl
- The '-template' flag is only valid when using 'go-template'
- A template must be supplied using '-template' when using go-
- Invalid value for "-out"; valid values are [go-template, jso
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/08474b36ceda156b.
Report an issue: GitHub.