Provisioning a datasource with token in environment variable

Following the documentation on the provision feature found here.

I have a datasource config file at /etc/grafana/provisioning/datasources/influxdb.yaml.

The contents of which is the following.

apiVersion: 1

datasources:
- name: InfluxDB
  type: influxdb
  uid: influxdb
  url: http://localhost:8086
  editable: true
  isDefault: true
  version: 1
  jsonData:
    defaultBucket: speed_tests
    httpMode: POST
    organization: internet_monitor
    version: Flux
    readOnly: true
  secureJsonData:
    token: $INFLUXDB_TOKEN

When I start grafana-server via systemctl or delete this datasource and restart grafana-server.

The InfluxDB datasource is created but the token is empty and unset.

How can I provide the INFLUXDB_TOKEN environment variable to the systemd managed daemon?

I’ve tried setting the value of this variable in /etc/sysconfig/grafana-server but this hasn’t worked either.

$ cat /etc/sysconfig/grafana-server
INFLUXDB_TOKEN=<REDACTED>

Figured it out.

If the grafana-server is being started via systemd you’ll find there’s a parameter called EnvironmentFile=.

Which in /lib/systemd/system/grafana-server.service you’ll find is set as follows by default.

[Service]
EnvironmentFile=/etc/default/grafana-server
User=grafana

This means you can add variables to /etc/default/grafana-server e.g.

INFLUXDB_TOKEN=<REDACTED>

Then this variable will be available to the config files in /etc/grafana/provisioing.

Sorry I want to do the same stuff as you but since I don’t know mostly anything I was hoping that maybe you could guide me