Checkly provides resources to eliminate code duplication and reduce maintenance overhead in your monitoring setup.
Code snippets
Code snippets allow you to reuse code across multiple checks without duplication. They work with setup & teardown scripts in API checks and browser checks.
Inline snippet definition
resource "checkly_snippet" "login-procedure" {
name = "Login"
script = <<EOT
await page.fill('#email', process.env.TEST_EMAIL)
await page.fill('#password', process.env.TEST_PASSWORD)
await page.click('#login-button')
EOT
}
File-based snippet definition (recommended)
resource "checkly_snippet" "login-procedure" {
name = "Login"
script = file("${path.module}/snippets/login.js")
}
Store your snippet in a separate file for better organization and syntax highlighting.
Environment variables
Environment variables store sensitive data like credentials or configuration values that can be used across checks and groups.
resource "checkly_check" "user-login" {
name = "User Login Flow"
type = "BROWSER"
activated = true
frequency = 5
environment_variables = {
TEST_EMAIL = "user@example.com"
TEST_PASSWORD = "secure-password"
API_BASE_URL = "https://api.example.com"
}
locations = ["us-west-1", "eu-central-1"]
script = file("${path.module}/scripts/login.spec.js")
}
Variables defined at check level are only available to that specific check.
resource "checkly_check_group" "ecommerce-flows" {
name = "E-commerce Flows"
activated = true
environment_variables = {
TEST_EMAIL = "user@example.com"
TEST_PASSWORD = "secure-password"
API_BASE_URL = "https://api.example.com"
}
locations = ["us-west-1", "eu-central-1"]
concurrency = 3
}
Variables defined at group level are inherited by all checks within that group.
Account-level environment variables via Terraform are coming soon. For now, use check or group-level variables for your monitoring setup.