1. Uptime Monitoring
  2. Use environment variables in uptime checks

Uptime Monitoring

Use environment variables in uptime checks

Use an environment variable when several uptime checks need the same header value. You can replace the value without editing each check.

Create a variable

  1. Open Environment variables and select Create environment variable.
  2. Enter a name, such as API_TOKEN, and enter its value.
  3. Select Secret for a credential. Leave it unchecked for a readable config value.
  4. Select Create variable.

Keep a copy of a secret before you save it. You cannot view it again, but you can replace it. Anyone in your organization who can edit uptime checks can use the variable in a check, including a check that sends requests to an endpoint they control.

Add the variable to a check

  1. Create or edit an uptime check.
  2. In HTTP request settings, add a custom header. For example, set the name to Authorization and the value to Bearer {{API_TOKEN}}. If your endpoint uses HTTP Basic Auth instead, enter {{API_TOKEN}} in HTTP Authorization Password and enter a username in HTTP Authorization Username. Both fields can use references.
  3. Save the check.

OnlineOrNot stores the reference in the check and sends the current value when the check runs. To rotate a credential, edit the variable and replace its value. The next run uses the new value. You do not need to edit the checks that use it.

Create the variable and check with Terraform

With Terraform 1.11 or newer, create a secret variable and use its computed reference in the check header:

terraform {
  required_version = ">= 1.11"
}

variable "api_token" {
  type      = string
  sensitive = true
  ephemeral = true
}

resource "onlineornot_environment_variable" "api_token" {
  name          = "API_TOKEN"
  type          = "secret"
  value         = var.api_token
  value_version = "rotation-1"
}

resource "onlineornot_uptime_check" "health" {
  name = "Authenticated health check"
  url  = "https://example.com/health"
  headers = {
    Authorization = "Bearer ${onlineornot_environment_variable.api_token.reference}"
  }
}

Supply api_token from a secure source when applying. The ephemeral input and write-only value keep the secret out of Terraform state and plan files; the check stores only {{API_TOKEN}}. To rotate the secret, provide its new value and change value_version. Terraform cannot detect changes to the secret made outside Terraform. The .reference attribute updates the check header if you rename the variable.

The Terraform resource supports secret variables only. To create a readable config variable instead, use the dashboard steps above or the environment variables API.

For syntax, limits, and supported fields, see the environment variables reference.