Website monitoring with statuscake and terraform

As part of operation ‘make my infrastructure look like an adult operates it’ I needed to add some basic uptime/availability checks to a few simple sites. After some investigation I came up with three options, Pingdom, which I’d used before in production and was comfortable with, and two I’d not used in the past Uptime Robot and Status Cake.

By coincidence I was also doing my quarterly check of which AWS resources Terraform supported and I noticed that a StatusCake Provider had recently been added so I decided to experiment with the two of them together.

Once you’ve installed terraform, which is well documented on their site, you’ll want to set up a statuscake account and note your apikey. First we’ll set up our credentials:

    $ mkdir config
    $ cd config

    cat <<EOF > config/secrets.tfvars
    username = "my_username"
    apikey = "MYSECUREKEY"

These should be kept private and not checked in to public version control. We’ll now declare the variables we’ll need to create the resources.

    cat <<EOF > config/
    variable "username" {}
    variable "apikey"   {}

Finally we’ll add a statuscake_test resource to create our monitoring. In this example we’ll check once every 5 minutes.

    cat <<EOF > config/
    provider "statuscake" {
        username = "${var.username}"
        apikey = "${var.apikey}"

    resource "statuscake_test" "puppetcookbook" {
        website_name = " homepage"
        website_url = ""
        test_type = "HTTP"
        check_rate = 300

With all our config written we can run terraform to see what it’ll do.

    $ terraform plan -var-file="config/secrets.tfvars" config/

    statuscake_test.puppetcookbook: Refreshing state... (ID: 34)

        check_rate:   "" => "300"
        paused:       "" => "0"
        test_id:      "" => "<computed>"
        test_type:    "" => "HTTP"
        timeout:      "" => "<computed>"
        website_name: "" => " homepage"
        website_url:  "" => ""

    Plan: 1 to add, 0 to change, 0 to destroy.

and then to apply the changes

terraform apply config/

Now when you login to your statuscake dashboard you’ll be able to see your new, automated, availability monitoring. It’d be nice to see Terraform providers added for some other related services, like UptimeRobot and Pingdom but this is a very welcome first step.