How to Monitor a URL with Terraform
Set up your first HTTP monitor with Oack's Terraform provider, add a Discord notification channel, and trigger a test alert — all from your terminal in about 10 minutes.
Prerequisites
- Terraform ≥ 1.5 — install guide. This tutorial uses v1.5.7.
- Oack account — sign up free and create your first team.
- Account API key — go to Account Settings → API Keys in the dashboard and create a key. It starts with
oack_acc_. - Account ID — visible on the Account Settings page.
- Discord webhook URL — in your Discord server go to Channel Settings → Integrations → Webhooks → New Webhook, copy the URL.
Step 1 — Configure the Provider
Create a new directory for your project and add the Terraform configuration. We'll use environment variables for credentials so they don't end up in version control.
mkdir oack-monitoring && cd oack-monitoring Export your Oack credentials:
export OACK_API_KEY="oack_acc_your_key_here"
export OACK_ACCOUNT_ID="your-account-uuid-here" Create the provider configuration:
terraform {
required_providers {
oack = {
source = "oack-io/oack"
version = "~> 0.3"
}
}
}
provider "oack" {
# Reads OACK_API_KEY and OACK_ACCOUNT_ID from environment
} Initialize the provider:
terraform init
You should see Terraform has been successfully initialized!
and the Oack provider downloaded.
Step 2 — Create a Team and Monitor
Add a team and an HTTP monitor that checks httpbin.org every 60 seconds.
resource "oack_team" "demo" {
name = "Terraform Demo"
}
resource "oack_monitor" "httpbin" {
team_id = oack_team.demo.id
name = "httpbin health"
url = "https://httpbin.org/status/200"
check_interval_ms = 60000
}
That's the minimum config — three required fields (team_id, name, url).
Defaults handle everything else: GET method, 10 s timeout, failure threshold of 3, SSL & domain expiry monitoring enabled.
Apply:
terraform apply
Type yes to confirm.
Terraform creates the team and monitor.
Step 3 — Verify the Monitor Is Running
Open the Oack dashboard. Your monitor will be at:
https://app-ru.oack.io/teams/<team_id>/monitors/<monitor_id>
You can grab the IDs from the Terraform state:
terraform output -json | jq
# Or read specific values:
terraform state show oack_team.demo
terraform state show oack_monitor.httpbin Within a minute you'll see the first probe result — a green UP status with latency breakdown for DNS, TCP connect, TLS, TTFB, and total time.
Step 4 — Add a Discord Notification Channel
Create a Discord alert channel and link it to the monitor so you get notified on state changes.
resource "oack_alert_channel" "discord" {
team_id = oack_team.demo.id
name = "Discord Alerts"
type = "discord"
config = {
webhook_url = var.discord_webhook_url
}
}
resource "oack_monitor_alert_channel_link" "httpbin_discord" {
team_id = oack_team.demo.id
monitor_id = oack_monitor.httpbin.id
channel_id = oack_alert_channel.discord.id
} Add the variable so you can pass the webhook URL without hardcoding it:
variable "discord_webhook_url" {
type = string
sensitive = true
} Apply with the webhook URL:
terraform apply -var="discord_webhook_url=https://discord.com/api/webhooks/YOUR_WEBHOOK_HERE" The Discord channel is now linked to your monitor. When the monitor goes DOWN or recovers, you'll get a notification in your Discord channel.
Step 5 — Trigger a Test Alert (Status Code)
Let's force the monitor to fail by telling it to only accept 201 responses — but httpbin returns 200.
resource "oack_monitor" "httpbin" {
team_id = oack_team.demo.id
name = "httpbin health"
url = "https://httpbin.org/status/200"
check_interval_ms = 60000
allowed_status_codes = ["201"] # ← httpbin returns 200, this will fail
failure_threshold = 1 # ← fail on the first bad probe
} terraform apply Within 60 seconds the monitor will transition to DOWN and you'll see a Discord notification with the monitor URL, expected vs actual status code, and error details.
Step 6 — Trigger a Test Alert (Latency)
Another way to trigger an alert: set an impossibly low latency threshold. Change the monitor to accept any status but fail if response takes more than 1 ms:
resource "oack_monitor" "httpbin" {
team_id = oack_team.demo.id
name = "httpbin health"
url = "https://httpbin.org/status/200"
check_interval_ms = 60000
latency_threshold_ms = 1 # ← 1 ms is impossible over the internet
failure_threshold = 1
} terraform apply The monitor will fail because no real HTTP request completes in 1 ms. You'll get another Discord alert showing the actual latency vs the 1 ms threshold.
Step 7 — Restore and Clean Up
Remove the restrictive settings to let the monitor recover:
resource "oack_monitor" "httpbin" {
team_id = oack_team.demo.id
name = "httpbin health"
url = "https://httpbin.org/status/200"
check_interval_ms = 60000
allowed_status_codes = ["2xx"]
} terraform apply The monitor will recover to UP and you'll get a recovery notification in Discord with the downtime duration.
To tear everything down when you're done:
terraform destroy What's Next
- Add more monitors for your real endpoints — see HTTP Monitoring
- Set up Slack, Telegram, or PagerDuty channels — see Alert Channels
- Configure on-call schedules — see On-Call Scheduling
- Browse all Terraform resources — see Terraform Provider