Listing Terraform Workspace Errors

Terraform is an open-source tool used to build, change and version infrastructure. It provides infrastructure as a code to give you a blueprint of your datacenter. You can define an execution plan to set the target state of your infrastructure and then deploy those changes.

We will use this workflow to see a list of Terraform Workspaces that have returned an error.

The workflow is triggered every time Terraform sends a notification

Setting Up The Workflow

  1. Edit the Trigger Node, and enable the HTTP

    • This will allow us to trigger the workflow when Terraform provides an error notification

2. Add a Custom Node

  • This custom node is used to extract the Workspace details from the Terraform notification

  • Select the input from the Trigger Node

  • Set the node type to Custom

  • Paste the following code in the node editor:

async function process(){ let {collection,region} = context;
let wsId= collection[0].workspace_id
let workspaceName = collection[0].workspace_name
let URL= ""+wsId+"/actions/apply"

3. Add a Report Node

  • This will be used to send the list of Workspaces with errors to your email/Slack

  • Select medium in which you want to receive the notification

4. Save and Deploy the Workflow, and copy the HTTP link generated in the Trigger Node

Connecting To Terraform

  1. Open Workspaces in Terraform

  2. Go to Settings --> Notifications --> Create Notification

  3. Set the name as Failed Workspace

    • Paste the HTTP link from the Trigger Node as Webhook URL

    • Select "Only certain events", and "Errored" inside it