Getting started with Terraform and StatusPal status pages

Learn how to provision your StatusPal status page, including monitoring and incident automation, with Terraform in this step-by-step guide.

Introduction

Terraform, created by HashiCorp, is a popular infrastructure-as-code software tool used to provision various types of infrastructure and services, including StatusPal status pages, monitoring checks, and incident automation.

This step-by-step guide teaches you how to set up StatusPal status pages with Terraform from the ground up, including the following resources:

  1. StatuPal status page

  2. Status page services

  3. Enable monitoring checks for your services

  4. Configure incident automation from external monitoring services

Before you begin

To use this guide, you should have some basic knowledge of both StatusPal and Terraform. If you don't have a StatusPal account, you can register here. Also, you will need to install the Terraform CLI.

1. Bootstrap Terraform and the StatusPal provider

Start by initializing a working directory and creating a Terraform configuration file:

mkdir terraform-statuspal && cd terraform-statuspal
touch main.tf

Next, instruct Terraform to install and use the StatusPal provider, by setting the terraform and required_providers blocks in main.tf:

terraform {
  # Require Terraform version >= 1.1.0
  required_version = ">= 1.1.0"

  # Require the latest version of the StatusPal provider
  # You can find it here: https://registry.terraform.io/providers/statuspal/statuspal/latest
  required_providers {
    statuspal = {
      source  = "statuspal/statuspal"
      version = "0.2.7"
    }
  }
}

In this code block, you're setting the required version of Terraform to 1.9.0 and setting the StatusPal provider to the latest version. Using the right version constraints for your setup will provide better stability with your Terraform runs.

Now that you've set your Terraform and StatusPal provider versions, you need to configure the StatusPal provider.

2. Configure the StatusPal provider

With terraform all set, configure the StatusPal provider with the following items:

  1. Your StatusPal API key, it can be a user API key or an organization API key.

  2. Your StatusPal region. It can be US or EU.

In main.tf, set those values on the provider:

By setting these values on the StatusPal provider, you're configuring that provider to make changes on behalf of your account through StatusPal APIs.

You can also configure the StatusPal provider using environment variables. This is a useful way to set default values for your provider configuration.

For more information about configuring the StatusPal provider, please feel free to check out our official provider documentation.

With your StatusPal provider configured, initialize Terraform:

When Terraform finishes installing and registering the StatusPal provider, you'll receive a success message and some actionable next steps, such as running terraform plan. Before you can run terraform plan, however, you need to create your resources.

3. Configure a status page with services

With the StatusPal provider configured and initialized, you can define a status page.

Using the statuspal_status_page resource you can create an example status page:

Now you should be able to test your configuration with a dry run:

You should see output that displays Terraform's execution plan. The plan contains the actions Terraform performs when your run terraform apply:

In this case, the plan shows you that Terraform will create a new status page when you run terraform apply. After verifying the details, execute the plan to provision the status page resource in your StatusPal account:

Every time you apply changes, Terraform asks you to confirm the actions you've told it to run. Type "yes".

While it's running, Terraform sends logs to your console:

Log in to StatusPal and navigate to /admin/orgs/:organization_id to confirm that Terraform created your new status page in your organization.


At this point you can add services to your status page:

Run terraform plan again to see what will happen if you apply the plan.

You should see the following output:

In this case, the plan shows you that Terraform will create 2 services when you run terraform apply. Maybe you already noticed, it's possible to create child services also. After verifying the details, execute the plan to provision the service resources in your example status page:

The same procedure is before, you need to write "yes" to approve the changes.

While it's running, Terraform sends logs to your console:

Again, you can navigate to /admin/status_pages/:status_page_subdomain/services to confirm that Terraform created your new services in your status page.

4. Configure StatusPal monitoring on a service

To configure StatusPal monitoring on a service you will need the change a few attributes. We will use the previously defined service as an example:

5. Configure 3rd-party monitoring with incoming webhook URL

To configure 3rd-party monitoring with incoming webhook URL on a service you will need the change a few attributes. We will use the previously defined service as an example:

After applying the plan with terraform apply you will be able to see the incoming webhook URL in the outputs:

If you run into any problems, feel free to hit us up at [email protected].

Last updated