Managing Datadog by hand is an incredibly tedious and error-prone process.
Writing an automated tool against Datadog’s API will pay dividends but it’s a hefty price to pay.
Thankfully there’s a better way. A much better way. That way is managing Datadog with Terraform, giving you automation (and more) for free.
You write your configuration in HCL (Hashicorp’s Configuration Language). You describe the components you want, for example “I want a DD monitor named disk_usage, for the metric system.disk.in_use, alerting at 85% and above”. TF then figures out and runs whatever changes are needed on your DD account to get to your described desired state.
And while HCL is a declarative language, it’s dynamic, providing features like variables; counts; conditions; types such as lists and maps; built-in functions like format — to format strings, join — to join list items with a delimiter, and element — to access list items; and modules. Therefore you don’t need a templating language in addition to your configuration language to make up for the latter’s shortcomings. When using a tool configured by YAML for example, you often need to use a templating language like Jinja2 with its conditions and loops to generate the working YAML. HCL is all you need.
You run Terraform with an easy-to-use CLI. Data-to-day you run a couple shell commands: plan and apply. Plan for TF to figure out the difference between what you want and you’ve got in DD and plan the changes needed to get to your desired state. And apply to run those changes on DD and get there.
Here’s an example showing how to create monitors and timeboards, using variables to have consistent alert messages, queries, and thresholds. You can follow along with this example repo. Clone it and run against a trial Datadog account (your own account is fine too if you don’t have monitors/timeboards with the same names).
What’s going on in the script/gist below:
You can read Terraform’s Datadog provider docs to learn the API’s details.
Terraform is a tool that pays compounding dividends. You start with a small investment, like Datadog, then Kubernetes, and AWS. While they can be managed separately, by connecting them together, you can compose your service’s infrastructure in a module. Now you can easily spin up all your infrastructure per environment — dev, staging, prod (even per IaaS — AWS and GCP).
Terraform is one of the best ops tools ever made. If you know it’s out there and don’t use it you’re a masochist. Even with Datadog it’s a big boon.
–
Please say hi at @travisjeffery.
Hit the 👏 if you found this useful, and feel free to share.
Thanks for reading.