Skip to content

TechOpsHub/terraform-uptime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Uptime Module

A comprehensive Terraform module for managing Uptime.com monitoring resources. This module supports multiple types of uptime checks including HTTP, API, Transaction, WHOIS, PageSpeed, and Group checks.

Features

  • Multiple Check Types: Support for HTTP, API, Transaction, WHOIS, PageSpeed, and Group checks
  • Tag Management: Automatic tag creation and management
  • Flexible Configuration: Configurable intervals, locations, contact groups, and thresholds
  • Resource Grouping: Ability to create groups of checks with custom down conditions
  • Conditional Creation: Optional resource creation with create variable

Supported Check Types

Type Description Required Variables
http HTTP/HTTPS endpoint monitoring address
api API endpoint monitoring with custom scripts script
transaction Multi-step transaction monitoring script
whois Domain expiration monitoring whois_address, expect_string
pagespeed Page speed performance monitoring script
group Group multiple checks together down_condition

Usage

Basic HTTP Check

module "uptime_check" {
  source = "./terraform-uptime"

  create   = true
  type     = "http"
  name     = "My Website"
  address  = "https://example.com"

  locations      = ["US-East", "US-West"]
  contact_groups = ["default"]
  interval       = 15
  timeout        = 60
  tags           = ["production", "website"]
  create_tags    = true
}

API Check with Custom Script

module "api_check" {
  source = "./terraform-uptime"

  create   = true
  type     = "api"
  name     = "API Health Check"
  script   = "var response = http.get('https://api.example.com/health'); assert(response.status == 200);"

  locations      = ["US-East", "EU-West"]
  contact_groups = ["api-team"]
  interval       = 5
  timeout        = 30
  tags           = ["api", "critical"]
  create_tags    = true
}

WHOIS Domain Check

module "domain_check" {
  source = "./terraform-uptime"

  create          = true
  type            = "whois"
  name            = "Domain Expiration Check"
  whois_address   = "example.com"
  expect_string   = "example.com"
  whois_threshold = 30

  contact_groups = ["domain-team"]
  tags           = ["domain", "expiration"]
  create_tags    = true
}

Group Check

module "group_check" {
  source = "./terraform-uptime"

  create         = true
  type           = "group"
  name           = "Website Group"
  down_condition = "ANY"
  select_by_tag  = true
  selected_tag   = ["website"]

  contact_groups = ["ops-team"]
  tags           = ["group", "website"]
  create_tags    = true
}

Inputs

Name Description Type Default Required
create Whether to create resources bool true no
type The check type (http, api, transaction, whois, pagespeed, group) string "" no
name The resource name string "" no
address HTTP Address to check string "" no
script Script to execute for check string "" no
locations Uptime locations to perform the check list(string) [] no
contact_groups Uptime contact groups list(string) [] no
interval Interval for checking (minutes) number 15 no
timeout Timeout in seconds number 60 no
is_paused Whether the check is paused bool false no
create_tags Whether to create tags bool false no
tags Tags for the resources any [] no
color_hex Color hex for the tag string "#18c7a1" no
select_by_tag Whether to select checks for group via tags bool true no
selected_tag Tag based on which group will select resources list(string) [] no
down_condition Down condition for the group string "ANY" no
whois_address The address to check the domain string "" no
expect_string The current domain registration info that should match string "" no
whois_threshold Raise an alert if there are less than this many days before the domain needs to be renewed number 20 no

Outputs

Name Description
uptime_resource_names List of all uptime resource names
uptime_resource_ids List of all uptime resource IDs

Requirements

Name Version
terraform >= 1.0
uptime 2.13.0

Providers

Name Version
uptime 2.13.0

Examples

Multiple HTTP Checks

module "website_checks" {
  source = "./terraform-uptime"

  for_each = {
    homepage = {
      type    = "http"
      name    = "Homepage Check"
      address = "https://example.com"
    }
    api = {
      type    = "http"
      name    = "API Check"
      address = "https://api.example.com/health"
    }
  }

  create          = each.value.create
  type            = each.value.type
  name            = each.value.name
  address         = each.value.address
  locations       = ["US-East", "US-West"]
  contact_groups  = ["default"]
  interval        = 15
  timeout         = 60
  tags            = ["production"]
  create_tags     = true
}

Transaction Check

module "transaction_check" {
  source = "./terraform-uptime"

  create = true
  type   = "transaction"
  name   = "Login Transaction"
  script = <<-EOT
    var response = http.get('https://example.com/login');
    assert(response.status == 200);

    var form = response.body.match(/<form[^>]*>/);
    assert(form != null);

    var loginResponse = http.post('https://example.com/login', {
      username: 'test',
      password: 'test'
    });
    assert(loginResponse.status == 200);
  EOT

  locations      = ["US-East", "EU-West"]
  contact_groups = ["qa-team"]
  interval       = 10
  timeout        = 120
  tags           = ["transaction", "login"]
  create_tags    = true
}

Notes

  • The module automatically creates tags when create_tags is set to true
  • Group checks can select resources either by tag (select_by_tag = true) or by explicit service names
  • WHOIS checks require both whois_address and expect_string to be set
  • API, Transaction, and PageSpeed checks require a script to be provided
  • The down_condition for groups can be set to "ANY" or "ALL"

License

This module is provided under the same license as the parent project.

About

Repository for the terraform-uptime configuration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages