HashiCorp Terraform Cloud
  • 11 May 2023
  • 3 Minutes to read
  • Dark
    Light
  • PDF

HashiCorp Terraform Cloud

  • Dark
    Light
  • PDF

Article summary

AlertOps and HashiCorp Terraform Cloud

Terraform is HashiCorp’s infrastructure as code tool. It lets you define resources and infrastructure in human-readable, declarative configuration files, and manages your infrastructure’s lifecycle.

 

AlertOps’ alert management system can be integrated with Terraform Cloud to receive and respond to all (predefined status mappings) alerts through email, SMS, push notification or phone alerts. AlertOps would ensure that the alert/job status would reach the appropriate team by using proper workflows, escalation policies and schedules. Based on your ruleset, incidents can be automatically opened and closed, depending on what kind of run progress Terraform Cloud reports.

 

The above scenario and scope for integration is due to the fact that AlertOps has a very flexible and simple API/Webhook configuration feature that can be leveraged with Terraform Cloud's, notification capabilities.

 

AlertOps - Inbound Integration

We can define rulesets in AlertOps so that Terraform Cloud can send out run progress alerts to the AlertOps platform. AlertOps would ensure based on these notifications received, that it would always reach out and assign to the correct person/team by utilizing its escalation policies, schedules, and workflow features.

 

AlertOps provides Inbound Integrations to integrate with numerous monitoring, chat and ITSM tools. You can configure an inbound integration for Terraform Cloud.

 

At a high level this is how the flow looks like, you define an API integration in the AlertOps platform by defining settings like Integration Name, Escalation rules, recipient users/groups. Once an integration is defined, a unique API URL is generated. This acts as webhook or the gateway through which notifications from Terraform Cloud reach AlertOps and thus an incident/alert is created correspondingly. The API can be defined with various settings like URL mappings, filters, escalations etc. as required. Terraform Cloud has to be defined with a Wehook notification trigger.


Configure Inbound Integration in AlertOps

  1. Navigate to Configuration àIntegrations àAdd API Integration à API Integration Detail page.
  2. Select Terraform Cloud
  3. Once you select the integration, you can then specify basic settings like the integration name, escalation policy, names of the recipients/groups for which the alerts must be assigned to.
  4. Once you click save, the API Integration will be created, and you will be given a unique URL which acts as the access point and needs to be configured at the source (in this case Terraform Cloud), to send alerts. You can find the integration you just created, and you can give advanced settings and define various configurations for the alerts to be received and processed. For example, you can define when to open and close alerts based on the payload obtained from the API call, filters etc.
  5. Make a note of the API URL, which will be used in Terraform Cloud, so it calls a HTTP POST request to this URL with the body in JSON format containing the alert specific information. AlertOps automatically creates an alert when the status variable (notifications_0^trigger) contains 'run:errored'. The incident will also be closed automatically when the status 'run:completed' is received from Terraform.
  6. You can similarly define URL mappings as you want, owing to the flexibility provided by AlertOps’ OpenAPI/Plug-and-Play integrations. You can provide other filters and match with regex expressions as well. You can also test the generated URL with the sample data provided.

 

Configure Integration in Terraform Cloud 

  1. Go to your desired workspace, under 'Settings' select 'Notifications'
  2. Select 'Create a Notification'
  3. Select Destination as 'Webhook'
  4. Give the URL as the AlertOps Inbound Integration API URL
  5. For Triggers, select 'All Events'
  6. Click 'Create a Notification', after creating it, make sure it is Enabled


Thats it! You have configured a Webhook notification and associated triggers with this endpoint. Any alert would now be sent to AlertOps for incident management.

Message logs, alert specific information can be viewed in the “Inbound Log” section in AlertOps Dashboard. Alerts can be viewed in the ‘Alerts’ tab as well.

 

Alert Triggering Information

AlertOps will automatically create an incident when a new alert is received from Terraform Cloud when the notifications_0^trigger field contains "run:errored".

 

If an alert with status "run:errored" matches an existing Open Alert, AlertOps will recognize the new alert as a duplicate and ignore the alert.

The alert will be recorded in the Inbound Messages table as “Mapped Appended.”

 

AlertOps will automatically close the same incident when an alert with notifications_0^trigger contains 'run:completed'.

 

References

AlertOps Integration Guides

General Restful API Guide

Terraform Cloud Support Docs


Was this article helpful?