SaC - How to build status pages as code with Terraform
Status pages are a clever solution to bundle all your services, and see the status of them at one sight. We at ilert took this one step further: why not build your status page as code using Terraform? We want to show you how we make it possible, and how you can set it up for your own infrastructure - a real SaC solution.
Hashicorp’s Terraform is widely used for deploying and manging infrastructure as code. In our previous blogpost to Terraform we covered all the basics for setting up the ilert Terraform Provider and an alerting infrastructure. If you need more in depth information on the setup or if you are stuck you can find more information there. We will now step through the whole process: from creating your first alert source to deploying a status page with automation rules via code with Terraform.
Requirements
You will need:
- a Mac / Unix machine
- an ilert account signup now, its free
Setup
A quick overview of what you need to set up:
- your ilert account
- a local installation of Terraform
Additionally, you will need to clone the example repository from GitHub.
You also need to provide your ilert credentials either as variables in terraform apply, or store it in a separate file named terraform.tfvars. Create a file in the repository root directory named terraform.tfvars, and Terraform will automatically detect and set those variables on every apply.
To finish your setup you have to initialize Terraform to use it in your directory. Simply run terraform init and the initialization should be done after provider installation.
ilert infrastructure
Before applying any code here’s an overview of the resources and their relations you will be creating in ilert.
In short: we send an event to an alert source which triggers an alert. An automation rule connects the alert source and a service by changing the services status when the alert source fires an alert. Therefore when the status of the service changes the statuspage will monitor this and display the current status of the service.
Create a status page
Setting-up
First you have to configure an alert source and provide an escalation policy.
Creating
To create a status page you also need a service which will be contained in the status page.
Note: A subdomain must be unique, you may have to change it to another fitting name.
Automate a status page
Firing an alert or setting the status of the service manually is not desirable in 24/7 monitoring. An automation rule fits in perfect for that task: it connects the alert source to our service and helps us to automatically change the status of our service on an incoming alert.
If you now run terraform apply you should see cli output like this:
You have successfully configured an alert source and an escalation policy and also built a statuspage containing a service while automating via automation rule.
Fire up your browser and visit example_statuspage.ilert.io to check out the page you have just created :)
Run the automation
To put everything to test you have to trigger an alert, means sending an event to the ilert events endpoint. For that you have to put in your alert source integration key into apiKey in event.json.
This key can be found in the terraform state file terraform.tfstate or in the ilert UI under the alert source.
Now you send the event to trigger an alert:
An alert was created, the automation rule detected this and set the status of our service to ‘Degraded’, hence the status page shows the outage.
Destroying all created infrastructure
By using terraform destroy all of the created resources will be destroyed and removed from your ilert account.
Note: If you haven’t resolved the alert triggered from the alert source you won’t be able to delete it. Please resolve the alert first.
Observability can be easy
Building your status page as code with the ilert Terraform Provider simplifies the process of building consistent observability for your own services a lot. An ilert status page gives you the important information at first sight while providing details when needed.
If you are interested in knowing more about ilert status pages - take a look at our docs.
A fully executable sample of the shown code can be found on Github in our corresponding example repository.