Description
Proposal
As of Nomad v1.9 the CLI is only configurable via environment variables: https://developer.hashicorp.com/nomad/docs/commands#environment-variables
Allowing configuration of the CLI via a config file would not only allow for more expressive config parameters, but also be easier for generating and distributing.
Since the CLI uses the api
package SDK, the api
package should honor all non-CLI-flag configuration files listed below.
Parameters
address
- Same asNOMAD_ADDR
/-address
region
- Same asNOMAD_REGION
/-region
namespace
- Same asNOMAD_NAMESPACE
/-namespace
tls{}
- Same as agent's for relevant settingsunsafe_skip_verify
- Same asNOMAD_SKIP_VERIFY
cli{}
no_color
- Same asNOMAD_CLI_NO_COLOR
Note there are no tokens or other secrets in the config file.
Mixing CLI and Agent configuration in a single file is not supported. This would encourage sharing the tls{}
block between the CLI and Agent, and the CLI should not use the same certificates as the Agent.
The CLI should output a warning when encountering a config file with client{}
or server{}
blocks in it.
Agents should log a warning when encountering a config file with a cli{}
block as this may indicate a misunderstanding or misconfiguration.
File Resolution Order
As with Nomad Agent configuration file parsing, the CLI should parse and combine multiple config files. The precedence is (so parsing should be done in reverse order):
- Specific CLI flags (e.g.
-address
) - Specific environment variables (e.g. NOMAD_ADDR)
-config
CLI flagNOMAD_CLI_CONF
environment variable.nomad.{json,hcl}
in the current directory$HOME/.config/nomad/config.{json,hcl}
on Unix or%APPDATA%\nomad\config.{json,hcl}
on Windows
Prior Art
@jrasell did a hackweek project on CLI contexts: main...jrasell/hack-context
See also internal RFC NMD-156
External
- Terraform - https://developer.hashicorp.com/terraform/cli/config/config-file
- Packer - https://developer.hashicorp.com/packer/docs/configure
- kubectl - https://kubernetes.io/docs/reference/kubectl/generated/kubectl_config/
Use-cases
- Configuring UI hints in [cli] UI URL hints for common CLI commands #24454