Datadog Agent and Terraform: Can Agent settings be fully controlled via Terraform variables?
0 reputation · 23 Mar 2023, 14:08 UTC
0 reputation · 23 Mar 2023, 14:08 UTC
Goal: Define a repeatable development environment in which the Datadog Agent’s configuration (API key, site, tags, autodiscovery rules, and resource limits) is expressed entirely through Terraform variables, eliminating the need for manual edits to datadog.yaml or ad‑hoc environment variable files.
Uncertainty: While the Datadog Terraform provider exposes resources for installing the Agent and setting common environment variables, it is unclear whether all Agent settings—particularly autodiscovery configurations, custom check definitions, and advanced eBPF features—can be overridden solely via provider arguments or if they still require mounting a configuration file or relying on host‑level env vars. Additionally, handling of secrets such as DD_API_KEY within a Terraform workflow raises questions about secret management integration and version compatibility between the provider release and the Agent binary used in the dev environment.
datadog.yaml mount?DD_API_KEY be supplied to the Agent in a repeatable Terraform‑driven workflow while avoiding hard‑coding in configuration files?32775 reputation · 24 Mar 2023, 00:58 UTC
Short answer: No. The Datadog Terraform provider can set most scalar Agent settings (API key, site, tags, resource limits) via DD_* environment variables, but it cannot fully replace the datadog.yaml file or the conf.d directory that are required for autodiscovery rules, custom checks, and advanced eBPF/system‑probe configurations. Those features still need file‑based configuration or templated mounts.
DD_API_KEY – API key for the AgentDD_SITE – Datadog site (e.g., datadoghq.com)DD_TAGS – Global tags applied to every metricDD_DOGSTATSD_PORT – Port for DogStatsDDD_PROCESS_CONFIG_ENABLED, DD_PROCESS_AGENT_ENABLED, DD_LOGS_ENABLED – Boolean flags for resource limits and featuresDD_* env vars in the Agent release notes.conf.d/*-autodiscovery.yaml files)conf.d)system-probe.yaml file)datadog.yaml” or “requires a config file”Never hard‑code the API key in a datadog.yaml or commit it to state. The recommended pattern is:
sensitive = true.
variable "dd_api_key" {
type = string
sensitive = true
}
terraform state show and checking the variable value is omitted.The provider’s datadog-agent module only exposes a handful of DD_* inputs. If you upgrade the Agent binary, new settings may appear that are not yet exposed by the provider. Always compare the DD_* list in the Agent release notes with the provider’s schema (terraform providers schema -json) to avoid silent mismatches.
# main.tf
module "dd_agent" {
source = "github.com/DataDog/terraform-datadog-aws//modules/datadog-agent"
dd_api_key = var.dd_api_key
dd_site = var.dd_site
dd_tags = var.dd_tags
dd_process_enabled = true
# No support for autodiscovery via this module
}
# user_data for EC2 (or container env for ECS)
data "template_file" "user_data" {
template = file("user_data.sh.tpl")
vars = {
DD_API_KEY = var.dd_api_key
DD_SITE = var.dd_site
DD_TAGS = var.dd_tags
}
}
resource "aws_instance" "agent" {
ami = var.ami
instance_type = var.instance_type
user_data = data.template_file.user_data.rendered
tags = {
Name = "dd-agent"
}
}
After terraform apply, run datadog-agent status on the host to confirm the effective configuration. Verify that the Agent is listening on the expected DogStatsD port and that the global tags appear in the Agent UI.
conf.d directory from a ConfigMap (K8s) or from a local file provisioner.local_file resource and mount it into the Agent container.template_file to generate system-probe.yaml and mount it.In short, Terraform can handle the “simple” env‑var knobs, but for the richer, structured configuration that Datadog’s Agent supports, you must still supply YAML files. The combination of Terraform variables for env vars and templated file mounts gives you a repeatable, declarative setup without manual edits.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.