Using Environment Variables in the Configurationedit

This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.

You can use environment variable references in the topbeat.yml file to set values that need to be configurable during deployment. To do this, use:

${VAR}

Where VAR is the name of the environment variable.

Each variable reference is replaced at startup by the value of the environment variable. The replacement is case-sensitive and occurs before the YAML file is parsed. References to undefined variables are replaced by empty strings unless you specify a default value. To specify a default value, use:

${VAR:default_value}

Where default_value is the value to use if the environment variable is undefined.

After changing the value of an environment variable, you need to restart Topbeat to pick up the new value.

Examplesedit

Here are some examples of configurations that use environment variables and what each configuration looks like after replacement:

Config source Environment setting Config after replacement

name: ${NAME}

export NAME=elastic

name: elastic

name: ${NAME:beats}

no setting

name: beats

name: ${NAME:beats}

export NAME=elastic

name: elastic

hosts: [$HOSTS]

export HOSTS="'localhost:9200', 'localhost:9202'"

hosts: ['localhost:9200', 'localhost:9202']

Troubleshootingedit

When logging is enabled at the info level or higher, a message is logged for each environment variable replacement. For example:

2016/01/13 23:00:27.925523 cfgfile.go:87: INFO Replacing config environment variable '${NAME}' with 'elastic'
2016/01/13 23:00:27.925786 cfgfile.go:87: INFO Replacing config environment variable '${HOSTS}' with ''localhost:9200', 'localhost:9202''