Developers

Terraform

Manage UptimeWarden monitors as HCL: checks, regions, thresholds and alert routing, with an API token.

The official UptimeWarden Terraform provider lets you declare your monitoring alongside the rest of your infrastructure: the same terraform plan, the same review process, the same state file.

Source: registry.terraform.io/uptimewarden/uptimewarden

The provider is on the Terraform Registry as uptimewarden/uptimewarden; terraform init installs it. The source code is at github.com/UptimeWarden/terraform-provider-uptimewarden.

What you can manage today

ResourceStatus
uptimewarden_monitorAvailable. Every monitor setting the dashboard has.
data.uptimewarden_monitorAvailable.
data.uptimewarden_escalation_policy, data.uptimewarden_webhookAvailable. Reference a policy or a webhook made in the dashboard by name.
uptimewarden_webhook_config, uptimewarden_status_page, uptimewarden_escalation_policy, uptimewarden_on_call_schedule, uptimewarden_api_token, data.uptimewarden_on_call_userComing in the next provider release. The API side is live (/api/v1/webhooks/configs, /api/v1/status-pages, /api/v1/on-call/…, /api/v1/api-tokens). Until the release, create these in the dashboard.

For the coming resources, give the provider's token the Infrastructure as Code preset (webhooks:*, status_pages:*, on_call:*, api_tokens:* and the monitor permissions). A token the provider creates gets only permissions the provider's token has and cannot outlive it. The API's webhook endpoints refuse an unknown field in the body with 400. The values of custom headers whose name looks like a credential come back as ***** in responses, and sending ***** back on an update keeps the stored value.

The provider talks to the public /api/v1 API with an API token (uptw_…). Everything it does goes through the same validation, defaults and plan limits as the dashboard, so a plan apply never gets a setting the UI would refuse.

Quick start

terraform {
  required_providers {
    uptimewarden = {
      source  = "uptimewarden/uptimewarden"
      version = "~> 0.1"
    }
  }
}

provider "uptimewarden" {
  # Token from the UW_API_TOKEN env var, or set api_token inline (not recommended).
}

resource "uptimewarden_monitor" "api" {
  name     = "Production API"
  type     = "http"
  url      = "https://api.acme.com/health"
  interval = 60
  timeout  = 10
  region   = "gwc"
}

Create a token in More › Developers › API & Tokens (the API tokens tab) with monitors:read, monitors:create and monitors:delete (the Monitor Manager group), then:

export UW_API_TOKEN="uptw_xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
terraform init && terraform apply

Provider configuration

AttributeDescriptionEnv var
api_token (sensitive)UptimeWarden API tokenUW_API_TOKEN
base_urlAPI base URL (default: https://app.uptimewarden.online)UW_API_URL (UW_BASE_URL also works)

uptimewarden_monitor

Manages an HTTP, TCP, UDP, SSL, WebSocket, gRPC, MCP, Ping, DNS or Heartbeat monitor. Each attribute is the snake_case form of the API field with the same meaning (expected_status_codes is expectedStatusCodes); the API reference lists every field and its rules.

resource "uptimewarden_monitor" "checkout" {
  name        = "Checkout API"
  type        = "http"
  url         = "https://api.acme.com/checkout/health"
  interval    = 60
  timeout     = 10
  external_id = "checkout-api"

  # Where it is checked from
  region                 = "gwc"
  verification_regions   = ["sea"]
  min_confirming_regions = 2

  # HTTP settings
  method                = "GET"
  custom_headers        = { "X-Probe" = "uptimewarden" }
  expected_status_codes = "200,201,204"
  expected_body         = "ok"
  follow_redirects      = true
  verify_ssl            = true

  # Thresholds
  response_time_threshold = 800
  ssl_expiry_days         = 14

  # Alert routing
  alert_types          = ["down", "recovery"]
  email_addresses      = "[email protected]"
  escalation_policy_id = "01J9ZP4M3K8Q5R6S7T8V9W0EP1" # publicId from the dashboard
  selected_webhook_ids = ["01J9ZP4M3K8Q5R6S7T8V9W0WH1"]
}

resource "uptimewarden_monitor" "backup_job" {
  name                    = "Nightly backup"
  type                    = "heartbeat"
  interval                = 86400
  heartbeat_grace_seconds = 1800
}

output "backup_ping_url" {
  value     = uptimewarden_monitor.backup_job.heartbeat_url
  sensitive = true
}

Required: name, type; url for every type except heartbeat.

Basics: description, interval (seconds; at least 30 and your plan's minimum; default 300), timeout (5-300, default 30), is_active, tags, external_id.

Regions: region takes an active code: gwc (Sweden), wus3 (Phoenix), sea (Hong Kong), brs (São Paulo), ae (Sydney). uaen is retired and refused. Choosing a region needs region selection on your plan. verification_regions are the regions that recheck an outage before it is alerted: active codes, not the primary, at most your plan's verification regions minus one. min_confirming_regions other than your plan's default needs a plan that allows it. GET /api/v1/regions returns the codes and your plan's allowance.

Check settings: method, custom_headers, request_body, expected_status_codes, expected_body, content_validation, follow_redirects, verify_ssl, enable_ssl, basic_auth_username, basic_auth_password (sensitive), bearer_token (sensitive), hostname, port, grpc_proto_file, grpc_method, dns_config (record_type, resolver, expected_answers), agent_id.

Thresholds: retry_count, response_time_threshold (50-5000 ms), ssl_expiry_days, ssl_alerts, domain_monitoring_enabled and domain_expiry_threshold (plan feature), security_analysis_enabled and security_analysis_mode (plan feature).

Alert routing: alert_types, notifications (channel × alert type), email_addresses, phone_numbers, whatsapp_numbers, voice_numbers, voice_mode (sequential or all), escalation_policy_id, selected_webhook_ids. Policies and webhooks are referenced by public id; only your own are accepted. Until their resources ship, list them with GET /api/v1/escalation-policies and GET /api/v1/webhooks. On-call escalation is a plan feature.

Heartbeat: heartbeat_interval_seconds (60 s to 30 days; defaults to interval), heartbeat_grace_seconds (default 60).

Computed: id (the public id), heartbeat_token and heartbeat_url (sensitive, heartbeat monitors), created_at.

A plan limit (monitor count, type, interval, region, verification, a feature) fails the apply with the plan's own sentence. Changing type is applied in place, except a change to or from heartbeat, which forces replacement. Nested settings (content_validation, ssl_alerts, dns_config, maintenance_windows) are attributes written with =, not blocks. Removing an optional attribute from your configuration keeps the value the API holds; to clear it, set it to its empty value. Region codes are checked by the API, so a new region needs no provider release.

Import:

terraform import uptimewarden_monitor.checkout 01J9ZP4M3K8Q5R6S7T8V9W0X1Y

data.uptimewarden_monitor

Reads an existing monitor by public id.

data "uptimewarden_monitor" "existing" {
  id = "01J9ZP4M3K8Q5R6S7T8V9W0X1Y"
}

output "monitor_url" {
  value = data.uptimewarden_monitor.existing.url
}

Heartbeats from your jobs

A heartbeat monitor's heartbeat_url is the success ping. When the job fails, call the same token's /fail so the incident opens now instead of after the interval and grace:

curl -fsS -X POST "https://app.uptimewarden.online/api/heartbeat/$TOKEN/fail" \
  -H "Content-Type: application/json" -d '{"message":"pg_dump exited 1"}'

See also

Bu sayfayı Türkçe okuyun