Skip to content

Instantly share code, notes, and snippets.

@jesusvazquez
Last active June 22, 2020 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusvazquez/73cac0191b3a627a4c84a072228af09d to your computer and use it in GitHub Desktop.
Save jesusvazquez/73cac0191b3a627a4c84a072228af09d to your computer and use it in GitHub Desktop.

Import datadog monitors using terraform

Template: terraform import <datadog-resource-name>.<name-that-we-give-to-the-resource>.<resource-id>

Example for monitors:

terraform import datadog_monitor.sidekiq_queued_jobs_express 2250497

Time to write HCL

  1. Get the JSON from the UI or use the API
  2. Save it to a file e.g. monitor1.json
  3. Run this command (requires json2hcl installed):
json2hcl < monitor1.json | sed -e 's/\"name\"/name/g' -e 's/\"type\"/type/g' -e 's/\"query\"/query/g' -e 's/\"message\"/message/g' -e 's/\"options\"/options/g' -e 's/\"notify_audit\"/notify_audit/g' -e 's/\"locked\"/locked/g' -e 's/\"timeout_h\"/timeout_h/g' -e 's/\"silenced\"/silenced/g' -e 's/\"include_tags\"/include_tags/g' -e 's/\"no_data_timeframe\"/no_data_timeframe/g' -e 's/\"new_host_delay\"/new_host_delay/g' -e 's/\"require_full_window\"/require_full_window/g'  -e 's/\"notify_no_data\"/notify_no_data/g' -e 's/\"renotify_interval\"/renotify_interval/g' -e 's/\"thresholds\"/thresholds/g' -e 's/\"critical\"/critical/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment