Telegraf config failing to load

what am i doing wrong?
followed:

Created /etc/default/telegraf with the variables

USER="alice"
INFLUX_URL="https://us-west-2-1.aws.cloud2.influxdata.com"
INFLUX_SKIP_DATABASE_CREATION="true"
INFLUX_PASSWORD="monkey123"

Created a config with

telegraf config > telegraf.conf

Modified that config with the specified values

[global_tags]
  user = "${USER}"

[[outputs.influxdb]]
  urls = ["${INFLUX_URL}"]
  skip_database_creation = ${INFLUX_SKIP_DATABASE_CREATION}
  password = "${INFLUX_PASSWORD}"

If i try to save that to influx, it complains about INFLUX_SKIP_DATABASE_CREATION

[root@ncwv-influxdb01 ~]# influx telegrafs create -n "Test telegraf config" -d "test telegraf config" -f /etc/telegraf.conf 
Error: failed to create telegraf config "Test telegraf config": 500 Internal Server Error: An internal error has occurred - check server logs

[root@ncwv-influxdb01 ~]# cat /var/log/messages | grep influxdb
Feb 17 21:19:34 ncwv-influxdb01 influxd-systemd-start.sh: ts=2022-02-18T02:19:34.770645Z lvl=warn msg="internal error not returned to client" log_id=0ZjbZWAl000 handler=error_logger error="Near line 131 (last key parsed 'outputs.influxdb.skip_database_creation'): expected value but found '$' instead"

So instead I wrapped ${INFLUX_SKIP_DATABASE_CREATION} with quotes, like the other examples. saved fine.

However, if I try to start telegraf, either with out without quotes around that var, it complains about it.

with quotes wrapping “${INFLUX_SKIP_DATABASE_CREATION}”:

[root@ncwv-influxdb01 log]# telegraf --config /etc/telegraf.conf 
2022-02-18T02:25:02Z I! Starting Telegraf 1.21.4
2022-02-18T02:25:02Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf.conf: error parsing influxdb array, line 131: (influxdb.InfluxDB.SkipDatabaseCreation) cannot unmarshal TOML string into bool

without quotes wrapping ${INFLUX_SKIP_DATABASE_CREATION}:

[root@ncwv-influxdb01 log]# telegraf --config /etc/telegraf.conf 
2022-02-18T02:25:32Z I! Starting Telegraf 1.21.4
2022-02-18T02:25:32Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf.conf: Error parsing data: line 131: invalid TOML syntax

what gives?

skip_database_creation expects a boolean, not a string, the final result in the config file must look like this skip_database_creation=true

I had a look at Environment variables docs and the following should work:
Env Variable:
INFLUX_SKIP_DATABASE_CREATION=true
config:

[[outputs.influxdb]]
  {...}
  skip_database_creation = ${INFLUX_SKIP_DATABASE_CREATION}
# it should work also without curly brackets, not sure if it makes a difference
# skip_database_creation = $INFLUX_SKIP_DATABASE_CREATION

so remove the quotes from the environment variable file for the boolean.

[root@ncwv-influxdb01 ~]# vim /etc/default/telegraf
USER="alice"
INFLUX_URL="https://us-west-2-1.aws.cloud2.influxdata.com"
INFLUX_SKIP_DATABASE_CREATION=true
INFLUX_PASSWORD="monkey123"

however when i try to run telegraf calling the conf, i still get an error

[root@ncwv-influxdb01 ~]# telegraf --config /etc/telegraf.conf 
2022-02-18T13:29:07Z I! Starting Telegraf 1.21.4
2022-02-18T13:29:07Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf.conf: error parsing influxdb array, line 131: (influxdb.InfluxDB.SkipDatabaseCreation) cannot unmarshal TOML string into bool

any other ideas? or am i misunderstanding?

so the configuration link i had been following must have been for influxdbv1, there’s another method for influxdbv2 as defined here:

This instead uses a token and a different output.

[[outputs.influxdb_v2]]
  urls = ["http://localhost:8086"]
  token = "$INFLUX_TOKEN"
  organization = "example-org"
  bucket = "example-bucket"

Once I filled these in and commented out [[outputs.influxdb]], telegraf began reporting correctly.

Hello @ carefreepineapple glad to see you resolved your problem. It is definitely recommended to use influxdb_v2.

In case anyone stumbles into this same problem, I was able to reproduce your error when I didn’t have INFLUX_SKIP_DATABASE_CREATION exported correctly. Are you using the Telegraf .deb or .rpm packages? In the documentation here: telegraf/CONFIGURATION.md at master · influxdata/telegraf · GitHub evidently to use /etc/default/telegraf that is a requirement. I assume you have to export your environment variables differently when using different packages.

The error that is returned isn’t very helpful, so I created a PR to give a more accurate error message: fix: error msg for missing env variables in config by sspaink · Pull Request #10681 · influxdata/telegraf · GitHub