Terraform Provider
Infrastructure as Code for Uptime Monitor
Complete Example
terraform {
required_providers {
uptime = {
source = "uptime-monitor-io/uptime"
version = "~> 0.0.8"
}
}
}
provider "uptime" {
api_key = var.uptime_api_key # or use env: UPTIME_API_KEY
}
# Email contact
resource "uptime_contact" "email" {
name = "DevOps Team"
channel = "email"
down_alerts_only = false
email_settings = {
email = "devops@example.com"
}
}
# Slack integration
resource "uptime_contact" "slack" {
name = "Slack #alerts"
channel = "slack"
slack_settings = {
webhook_url = var.slack_webhook_url
}
}
# PagerDuty for critical alerts
resource "uptime_contact" "pagerduty" {
name = "PagerDuty On-Call"
channel = "pagerduty"
pagerduty_settings = {
integration_key = var.pagerduty_key
auto_resolve_incidents = true
}
}
# HTTPS monitor with all options
resource "uptime_monitor" "api" {
name = "Production API"
url = "https://api.example.com/health"
type = "https"
check_interval = 60 # seconds
timeout = 30 # seconds
fail_threshold = 2 # regions must fail
regions = ["us-east-1", "us-west-1", "eu-west-1"]
contacts = [
uptime_contact.email.id,
uptime_contact.slack.id,
uptime_contact.pagerduty.id
]
https_settings = {
method = "POST"
expected_status_codes = "200,201"
check_certificate_expiration = true
follow_redirects = true
# Authentication
basic_auth_username = var.api_username
basic_auth_password = var.api_password
# Headers
headers = {
"Content-Type" = "application/json"
"X-API-Key" = var.api_key
}
# Request body
body = jsonencode({
test = true
})
# Response validation
expected_response_body = "\"status\":\"ok\""
expected_response_headers = {
"X-API-Version" = "v2"
}
}
}
# TCP monitor
resource "uptime_monitor" "database" {
name = "PostgreSQL"
url = "db.example.com:5432"
type = "tcp"
check_interval = 120
timeout = 10
regions = ["us-east-1"]
contacts = [uptime_contact.email.id]
tcp_settings = {}
}
# Ping monitor
resource "uptime_monitor" "gateway" {
name = "Network Gateway"
url = "10.0.0.1"
type = "ping"
check_interval = 60
timeout = 5
regions = ["us-east-1"]
contacts = [uptime_contact.email.id]
ping_settings = {}
}
# Status page with custom domain
resource "uptime_status_page" "public" {
name = "Service Status"
custom_domain = "status.example.com" # Add CNAME → status.uptime-monitor.io
monitors = [
uptime_monitor.api.id,
uptime_monitor.database.id,
uptime_monitor.gateway.id
]
period = 30 # 7, 30, or 90 days
show_incident_reasons = true
}
# Protected internal status page
resource "uptime_status_page" "internal" {
name = "Internal Systems"
basic_auth = "${var.status_username}:${var.status_password}"
monitors = [
uptime_monitor.database.id,
uptime_monitor.gateway.id
]
period = 90
show_incident_reasons = true
}
# Data sources to reference existing resources
data "uptime_monitor" "existing" {
id = "monitor_id_here"
}
data "uptime_account" "current" {}
# Outputs
output "status_page_url" {
value = uptime_status_page.public.url
}
output "monitor_count" {
value = data.uptime_account.current.max_monitors
}
Available Regions
us-east-1
us-east-2
us-west-1
us-west-2
ca-central-1
eu-west-1
eu-west-2
eu-west-3
eu-central-1
eu-north-1
ap-southeast-1
ap-southeast-2
ap-northeast-1
ap-south-1
sa-east-1
Import Existing
terraform import uptime_monitor.api MONITOR_ID
terraform import uptime_contact.email CONTACT_ID
terraform import uptime_status_page.public STATUS_PAGE_ID