The sartar Terraform provider

The provider lets you describe your monitoring as code: folders, monitors, scenarios, notification channels, lists, schedules and policies, roles and users. It works with Terraform and with OpenTofu. Every terraform command on this page works the same with tofu.

Install

There is nothing to download by hand. Declare the provider, and terraform init installs it.

terraform {
  required_providers {
    sartar = {
      source  = "sartar.app/harskogr/sartar"
      version = "~> 3.0"
    }
  }
}
terraform init

terraform init finds the provider from the host name in source, downloads the build for your platform, and verifies its signature and its checksum. It then records the checksums in .terraform.lock.hcl. Commit that file.

The source must be written in full, host name included. The provider is served by sartar, not by the public Terraform registry.

Supported platforms

Linux, macOS, Windows and FreeBSD, on amd64 and arm64. Linux, Windows and FreeBSD are also built for 386, and Linux and FreeBSD for arm.

Signing key

Releases are signed with this key. terraform init prints its identifier when it installs the provider.

Key ID       FDC7EE9C5F903C58
Fingerprint  598F C4D4 D2CB 22E0 A197  7BD3 FDC7 EE9C 5F90 3C58

Without network access

Download the archive of the provider on a machine that has access:

https://sartar.app/dl/terraform-provider-sartar/<version>/terraform-provider-sartar_<version>_<os>_<arch>.zip

Then extract it into the plugin directory of Terraform:

~/.terraform.d/plugins/sartar.app/harskogr/sartar/<version>/<os>_<arch>/

Configure

The provider needs an API key, and nothing else. Create the key in the web dashboard: account menu, API keys, Create key. See Before you start.

provider "sartar" {
  token = var.sartar_token
}

variable "sartar_token" {
  type      = string
  sensitive = true
}
Argument Value
token your API key

Keep the key out of your repository: leave token out of the configuration and give it through the SARTAR_TOKEN environment variable instead. The provider block is then empty.

provider "sartar" {}
export SARTAR_TOKEN=<your API key>
terraform plan

Which key for which command

Command Key needed
terraform plan, terraform import, refresh a Read-only key is enough
terraform apply, terraform destroy a Read / write key

A good habit is to plan with a read-only key, and to keep the read / write key for the apply step of your pipeline.

A first configuration

This creates a folder, a notification channel, and a monitor inside the folder that alerts on the channel.

resource "sartar_folder" "prod" {
  name  = "Production"
  notes = "Customer-facing endpoints."
}

resource "sartar_notification_channel" "slack" {
  type = "slack"
  name = "ops-alerts"
  config = {
    webhook_url = var.slack_webhook_url
  }
}

variable "slack_webhook_url" {
  type      = string
  sensitive = true
}

resource "sartar_monitor" "api_health" {
  name    = "api health"
  url     = "https://api.example.com/health"
  period  = 60
  regions = ["fr"]
  folder  = "/${sartar_folder.prod.name}"

  http_check = {
    status_code = "200"
  }

  notification = {
    channel_id = sartar_notification_channel.slack.id
  }
}
terraform plan
terraform apply

Writing the folder as "/${sartar_folder.prod.name}" rather than as plain text tells Terraform that the monitor depends on the folder. The folder is then always created first.

Resources

Resource What it manages
sartar_folder a folder, and the settings inherited by what it contains
sartar_monitor an HTTP monitor
sartar_scenario a scenario and its steps
sartar_notification_channel a Slack, PagerDuty, Google Chat, Telegram or webhook alert target
sartar_notification_list a named group of alert targets
sartar_notification_schedule when the account is on hours
sartar_notification_policy what follows an alert: on-hours and off-hours profiles, reminders, escalation
sartar_mailbox an inbound e-mail address
sartar_role a named set of permissions
sartar_user a user of the account and their role
sartar_account_settings the default settings of the account
sartar_account_properties the properties of the account

sartar_folder

Attribute Type Notes
id string, computed uuid of the folder
name string, required unique in the account, must not contain /
notes string
parent_uuid string the parent folder, omitted for a folder at the root
properties map of strings
notification object alerting inherited by everything inside, same shape as on a monitor
policy_id number the notification policy this level follows; omit to inherit
resource "sartar_folder" "prod_eu" {
  name        = "Production EU"
  parent_uuid = sartar_folder.prod.id
}

sartar_monitor

Attribute Type Notes
id string, computed uuid of the monitor
name string, required
url string, required
period number seconds between two checks
regions set of strings exactly one region
enabled bool true by default
is_manual bool never scheduled, run on demand only
notes string
folder string path of the folder, such as /prod/edge. Empty means the root
calendar object restricts the schedule. See below
properties map of strings
http_request object method, body, preserve_cookies, real_hostname, headers
http_check object status_code, trust_certificate, retry, follow_redirect, and the checks on the response: headers, cookies, body, body_json
notification object the alert target. See below
policy_id number the notification policy this level follows; omit to inherit
type string omit for an HTTP check, tcp.connect for a TCP port check, external.report for a monitor your own script reports to (external reports), heartbeat.inbound for a heartbeat your job calls at a fixed time (heartbeats). Immutable: changing it replaces the monitor
type_config_json string the JSON config of a tcp.connect check: jsonencode({ host = "db.internal", port = 5432, tls = false, expect = { mode = "prefix", value = "220" } }) (expect and serverName optional) — or of an external.report: jsonencode({ expectEvery = 86400, graceSeconds = 1800 }) (both optional, in seconds) — or of a heartbeat.inbound: jsonencode({ lateAfter = 3600, lostAfter = 14400 }) (also notifyLost, acceptFailure; seconds, lateAfter 60 to 7200, lostAfter above it and at most 21600)
heartbeat_url string computed, sensitive: the url a heartbeat.inbound job calls, refreshed on every read (with a key that may update the monitor)
heartbeat_headers map sensitive: the headers a call must carry, name → value. read back on every refresh, values included (with a key that may update the monitor)

Changing folder to a path that does not exist makes the apply fail. Create the folder first with sartar_folder, and reference it — folder = "/${sartar_folder.prod.name}" — so Terraform creates it before the monitor.

Schedule. Omit calendar to check around the clock.

# Weekdays only, from 08:00 to 18:00.
calendar = {
  days = [1, 2, 3, 4, 5]   # 0 is Sunday, 6 is Saturday
  from = "08:00"
  to   = "18:00"
}

# Once a day, at a fixed time. `period` is then ignored.
calendar = {
  daily_at = "02:30"
}

Request and checks.

http_request = {
  method = "POST"
  body   = "{\"ping\":true}"
  headers = [
    { header = "Content-Type", value = "application/json" },
  ]
}

http_check = {
  status_code = "2xx"
  body_json = [
    { key = "status", operator = "equals", value = "up" },
  ]
}

status_code accepts an exact code such as "200", or a class such as "2xx". retry and follow_redirect are true by default. Set one to false to turn it off.

Connect to a given address. real_hostname makes the check connect to this address — an IP, or another host name — instead of resolving the host of url. The host name of url is still sent, as the Host header and as the TLS SNI, and the certificate is judged against it. Use it to check one server behind a load balancer, or a site without depending on its DNS.

http_request = {
  real_hostname = "203.0.113.10"
}

Checks on the response. Each row of headers, cookies, body and body_json names an operator; negate = true inverts it. The operators without a value (present, empty, isJson, the is… ones) take no value. Any other operator is refused at apply.

operator headers, cookies body body_json
present ✓ ✓
equals, contains, startsWith, endsWith ✓ ✓ ✓
matches (regular expression, RE2 syntax) ✓ ✓ ✓
empty ✓ ✓
isJson ✓
isInteger, isText, isBoolean, isArray, isEmptyArray, isNonEmptyArray ✓

The key of a body_json row is a path of object keys joined by dots: status, or checks.database.status for {"checks":{"database":{"status":"ok"}}}. There is no array index and no escaping, so a key that contains a dot cannot be reached. A body that is not JSON fails the check as a wrong body; a JSON body without the key fails it as a missing key.

A TCP port. url may be left empty: the API derives tcp://host:port.

type             = "tcp.connect"
url              = ""
type_config_json = jsonencode({
  host   = "imap.example.net"
  port   = 993
  tls    = true
  expect = { mode = "prefix", value = "* OK" }
})

Nothing is ever sent: only the connection, the TLS session (tls, with the certificate judged as for a web site; serverName is the name it must carry, the host by default) and the server's greeting (expect, whose mode is contains, prefix or regex) are judged. expect only makes sense for a protocol whose server speaks first (SMTP, IMAP, POP, FTP, SSH): on an HTTP or HTTPS port nothing arrives before a request, so such a check ends in a first byte timeout. Some ports (mail, directory, SSH, RDP) wait for the operator's approval: the monitor is created in standby and starts once approved.

An external report. Sartar runs nothing: your own script reports the result (sartar monitor report, or POST /monitors/{uuid}/results — see external reports). url is empty; regions and period are not needed. expectEvery makes a missing report an alert once the deadline plus graceSeconds (10 % by default, at least 30 s) has passed; without it, silence never alerts.

type             = "external.report"
url              = ""
type_config_json = jsonencode({
  expectEvery  = 86400
  graceSeconds = 1800
})

A heartbeat. Your job calls heartbeat_url around the time set by calendar.daily_at; Sartar alerts when nothing came by lateAfter and calls it lost at lostAfter (see heartbeats).

type             = "heartbeat.inbound"
url              = ""
calendar         = { daily_at = "02:00" }
type_config_json = jsonencode({ lateAfter = 3600, lostAfter = 14400 })
heartbeat_headers  = { "X-API" = var.backup_token }

Alert target. Set exactly one of email, channel_id, channel_name, list_id or list_name.

notification = {
  channel_name         = "ops-alerts"
  checks_before_alert  = 2
  checks_before_resume = 1
}

Omit a block to keep what the monitor inherits from its folders and from the defaults of the account.

sartar_scenario

Attribute Type Notes
id string, computed uuid of the scenario
name string, required unique in the account
region string one region for all the steps
period number seconds between two runs
enabled, is_manual, notes, folder, calendar same as on a monitor
notification object same shape as on a monitor
policy_id number the notification policy this level follows; omit to inherit
steps list, required the steps, in order

A step is either a check or a pause.

resource "sartar_scenario" "checkout" {
  name   = "checkout flow"
  region = "fr"
  period = 600

  steps = [
    {
      type = "monitor"
      name = "login"
      url  = "https://example.com/login"
      http_request = {
        method = "POST"
        body   = "{\"user\":\"demo\"}"
      }
      http_check = {
        status_code = "2xx"
      }
    },
    {
      type        = "wait"
      min_seconds = 3
      max_seconds = 8
    },
    {
      type = "monitor"
      name = "dashboard"
      url  = "https://example.com/dashboard"
      http_check = {
        status_code = "200"
        body = [
          { operator = "contains", value = "Welcome" },
        ]
      }
    },
  ]
}

A scenario alerts when the outcome of a run changes, from success to failure or back. It does not alert for each step.

Any change to a scenario recreates all of its steps.

sartar_notification_channel

Attribute Type Notes
id string, computed
type string, required slack, pagerduty, googlechat, telegram or webhook. Changing it replaces the channel
name string, required
config map of strings, sensitive depends on the type
Type Keys of config
slack heartbeat_url
pagerduty routing_key
googlechat webhook_url
telegram bot_token (the token @BotFather gives) and chat_id (the numeric id of the group or channel, e.g. -1001234567890, or a public channel's @username — the bot must be a member)
webhook url, method, body

sartar_notification_list

A list delivers an alert to every one of its members. Each member sets exactly one of channel_id, channel_name or email.

resource "sartar_notification_list" "oncall" {
  name = "on-call"
  members = [
    { channel_id = sartar_notification_channel.slack.id },
    { email = "alice@example.com" },
  ]
}

An e-mail address must belong to a user of the account. A list that something still alerts to cannot be deleted.

sartar_notification_schedule

A schedule says when the account is on hours. Outside its slots, and all day on an exception date, the account is off hours.

Attribute Type Notes
id number, computed
name string, required unique in the account
timezone string, required an IANA name such as Europe/Paris
slots list of objects the on-hours slots: days, from, to. Several a day are allowed; none crosses midnight
exceptions list of strings dates, YYYY-MM-DD, that are off hours all day
resource "sartar_notification_schedule" "office" {
  name       = "Office hours"
  timezone   = "Europe/Paris"
  slots      = [{ days = ["mon", "tue", "wed", "thu", "fri"], from = "09:00", to = "18:00" }]
  exceptions = ["2026-12-25"]
}

days takes mon, tue, wed, thu, fri, sat and sun; from and to are HH:MM in the schedule's time zone.

sartar_notification_policy

A policy says what follows an alert, with one profile for on hours and one for off hours. A folder, a monitor or a scenario follows it through policy_id, and the account through the policy key of its settings.

Attribute Type Notes
id number, computed
name string, required unique in the account
schedule_id number the schedule that says when the account is on hours; omit for a policy that is always on hours
on_hours object, required the on-hours profile. See below
off_hours object, required the off-hours profile, same shape

A profile:

Key Notes
mode notify, silent_digest or mute
reminders optional, with notify only: first_delay_min 15, 30, 60, 180 or 360; interval_min 60, 180 or 360; stop_after_min 180, 360, 720 or 1440. The first delay and the interval must be shorter than the stop
escalation optional, with notify only: type and target as on an alert target — email and the address of a user of the account, the type of a channel (slack, pagerduty, googlechat, telegram, webhook) and its id, or list and the id of a list — and delay_min 15, 30, 60, 120, 180 or 360
resource "sartar_notification_policy" "prod" {
  name        = "Prod"
  schedule_id = sartar_notification_schedule.office.id

  on_hours = {
    mode       = "notify"
    reminders  = { first_delay_min = 30, interval_min = 60, stop_after_min = 360 }
    escalation = { type = "slack", target = sartar_notification_channel.ops.id, delay_min = 60 }
  }

  off_hours = { mode = "silent_digest" }
}

The reminders and the escalation both count from the first notification; sending the escalation ends the reminders, and acknowledging the alert stops both. Under silent_digest the alert is listed in the digest sent when on hours come back, and what is still open is alerted then; under mute nothing is said.

A policy that something still follows cannot be deleted, nor can a schedule a policy still uses.

sartar_mailbox

An e-mail address that receives mail for your account. You choose the name, and sartar generates the address.

resource "sartar_mailbox" "signup" {
  name = "signup-flow"
}

output "signup_address" {
  value = sartar_mailbox.signup.address
}

Mailboxes must be enabled on your account.

sartar_role and sartar_user

A role is a named set of permissions. rights maps a kind of object to the actions allowed on it.

resource "sartar_role" "ci" {
  name        = "CI scenarios"
  description = "Runs scenarios and reads their results"
  rights = {
    scenario = ["read", "run", "progress"]
  }
}

resource "sartar_user" "alice" {
  email   = "alice@example.com"
  role_id = sartar_role.ci.id
}

A user can also take one of the built-in roles with role = "administrator", "editor" or "reader".

A new user receives a welcome e-mail and stays pending until they accept it: before that, they cannot sign in and receive no e-mail, alerts included. The read-only status attribute says pending, then active; it may take other values later, so do not match it exhaustively.

The key Terraform runs with can never grant more than it holds itself.

sartar_account_settings and sartar_account_properties

Both exist once per account. Declare each at most once.

resource "sartar_account_properties" "account" {
  properties = {
    env = "prod"
  }
}

sartar_account_properties owns the whole map: a key you remove from the configuration is removed from the account.

sartar_account_settings takes its values as JSON, in settings_json. Only the keys you state are managed: a plan compares them with the account and ignores the others. A setting changed by hand shows up in the next plan when you manage it, and stays quiet when you do not.

A key you remove from it keeps its last value. To change a setting back, state the value you want.

The key policy is the default notification policy of the account: the id of a sartar_notification_policy, or null for none.

resource "sartar_account_settings" "account" {
  settings_json = jsonencode({
    policy = sartar_notification_policy.prod.id
  })
}

Data sources

Data source Use
sartar_regions the regions your account can use
sartar_notification_channel a channel that Terraform does not manage, found by name
sartar_mailbox a mailbox found by name, to read its address
data "sartar_notification_channel" "ops" {
  name = "ops-alerts"
}

resource "sartar_monitor" "web" {
  name    = "example.com"
  url     = "https://example.com"
  period  = 300
  regions = ["fr"]

  notification = {
    channel_id = data.sartar_notification_channel.ops.id
  }
}

Import one object

Every resource can be imported by its identifier. For a folder, a monitor or a scenario, this is its uuid. The sartar CLI prints it:

sartar monitor show --name "/prod/api health" --quiet
terraform import sartar_monitor.api_health <uuid>

The two account resources import with the identifier account.

Adopt an existing account

You already have monitors, and you want Terraform to manage them without creating a second copy. The web dashboard writes the configuration for you, and the CLI tells Terraform which existing object each resource is.

You need the sartar CLI for step 3.

1. Export the account

In the web dashboard, open the account menu and choose Export to Terraform. Save the document as sartar.tf, in a directory of its own.

Choose a private directory. The state file of Terraform will be written next to sartar.tf, and it holds every secret of the configuration in clear text.

The export contains everything the provider can manage, except the users.

2. Fill in the secrets

No secret is written in sartar.tf. The export replaces each of them with a variable:

When the account holds at least one secret, the export shows a second tab, sartar-secrets.auto.tfvars. It holds the values of the secrets. Download this file and save it next to sartar.tf. Terraform loads it without any option.

Never commit this file. Add *.auto.tfvars to your .gitignore.

You can also give a value through the environment:

export TF_VAR_channel_slack_alerts_webhook_url='https://hooks.slack.com/services/…'

A private parameter of a scenario is optional. Without a value, the one stored in the account is kept. Reading these values requires the right to reveal private parameters; without it, their lines stay commented out.

Every other secret is required. Terraform stops until each has a value.

3. Generate the import blocks

sartar terraform imports --file sartar.tf > imports.tf

The CLI matches each resource of the document with the object of the same name in your account. It writes one import block for each match. What it cannot match with certainty is left out and listed in a comment at the end of the file. Nothing is guessed.

A read-only key is enough.

On Windows PowerShell 5.1, > writes the file in UTF-16, which Terraform cannot read. Write it in UTF-8 instead:

[Console]::OutputEncoding = [Text.Encoding]::UTF8
[IO.File]::WriteAllText("$PWD\imports.tf", (sartar terraform imports --file sartar.tf | Out-String))

PowerShell 7 writes UTF-8 with >: nothing to change there.

4. Read the plan

terraform init
terraform plan

You want a plan that imports, and changes nothing. If a required secret has no value, Terraform stops and names the variable.

Any other change means the document and the account disagree. Fix the document, then plan again.

5. Apply once

terraform apply

This step needs a read / write key. Afterwards, delete imports.tf. It has done its job.

From now on the configuration is the reference. Edit the .tf files, plan, then apply.

Upgrade the provider

Raise the version constraint if needed, then:

terraform init -upgrade

The provider and the platform must agree on the version of the API. When they no longer do, Terraform stops with this message:

Error: Provider and sartar API versions have diverged

Upgrading the provider fixes it.

Good to know