Terraform
Version-control your monitoring configuration alongside your infrastructure using Terraform's null_resource with local-exec.
DeadPing monitors can be managed as infrastructure-as-code using the REST API with Terraform. Define monitors alongside your infrastructure, version them in git, and apply changes through your existing Terraform workflow instead of clicking through a dashboard.
Creating Monitors
deadping.tf
variable "deadping_api_key" {
type = string
sensitive = true
}
resource "null_resource" "deadping_backup_monitor" {
provisioner "local-exec" {
command = <<-EOT
curl -sf -X POST https://deadping.io/api/monitors \
-H "X-API-Key: $DEADPING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "prod-db-backup",
"expected_interval_seconds": 86400,
"grace_period_seconds": 600,
"cron_expression": "0 2 * * *"
}'
EOT
environment = {
DEADPING_API_KEY = var.deadping_api_key
}
}
}
resource "null_resource" "deadping_billing_monitor" {
provisioner "local-exec" {
command = <<-EOT
curl -sf -X POST https://deadping.io/api/monitors \
-H "X-API-Key: $DEADPING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "billing-sync",
"expected_interval_seconds": 3600,
"grace_period_seconds": 120
}'
EOT
environment = {
DEADPING_API_KEY = var.deadping_api_key
}
}
}Terraform Cloud / Workspaces
In Terraform Cloud, set deadping_api_key as a sensitive variable in your workspace settings. Never commit .tfvars files containing secrets.
Lifecycle Management
For full create/destroy lifecycle, add a destroy-time provisioner to clean up monitors when infrastructure is torn down:
deadping-lifecycle.tf
resource "null_resource" "deadping_etl_monitor" {
provisioner "local-exec" {
command = <<-EOT
curl -sf -X POST https://deadping.io/api/monitors \
-H "X-API-Key: $DEADPING_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"prod-etl-pipeline","expected_interval_seconds":3600,"grace_period_seconds":300}'
EOT
environment = {
DEADPING_API_KEY = var.deadping_api_key
}
}
provisioner "local-exec" {
when = destroy
command = <<-EOT
MONITOR_ID=$(curl -sf https://deadping.io/api/monitors \
-H "X-API-Key: $DEADPING_API_KEY" | \
jq -r '.[] | select(.name == "prod-etl-pipeline") | .id')
if [ -n "$MONITOR_ID" ]; then
curl -sf -X DELETE "https://deadping.io/api/monitors/$MONITOR_ID" \
-H "X-API-Key: $DEADPING_API_KEY"
fi
EOT
environment = {
DEADPING_API_KEY = var.deadping_api_key
}
}
}