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.
You will need:
A quick overview of what you need to set up:
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.
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.
First you have to configure an alert source and provide an escalation policy.
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.
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 :)
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.
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.
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.