Using Environment Variables in Datadog Agent Configuration
1 min read
209 words
Hey there, 👋
I needed to set up a Datadog agent to check remote Postgres instances as a regular container. All the documentation I found was about injecting secrets like passwords or hostnames via Kubernetes secrets. This seemed to be the only way to do it besides using Docker Swarm secrets. Since I had to set up a container definition for AWS ECS Fargate, neither of these options were available. So I wanted to see if I could use "regular" environment variables from which the agent could pull the secrets on startup.
In the depths of the datadog-agent GitHub repository I found the possibility to use ENVs on startup to configure the agent to start e.g. the postgres database checks. This should not only work in the shown postgres configuration, but be a feature available for the whole datadog-agent.
The syntax is simple. Use %%env_<VARIABLE_NAME>%%
- this way the datadog-agent
knows where to get the environment variables from.
The following is the Docker label to use to set up additional remote checks in the datadog agent.
com.datadoghq.ad.checks='{"postgres": {
"init_config": {},
"instances": [{
"dbm": true,
"host": "%%env_POSTGRES_HOST%%",
"port": 5432,
"username": "datadog",
"password": "%%env_POSTGRES_PASSWORD%%",
"tags": ["dbinstanceidentifier:<DB_INSTANCE_NAME>"]
}]
}}'
Thanks for reading & have a nice day! 👋
Niklas