Run Tasks Integration
Note: Run Tasks is a paid feature, available as part of the Team & Governance upgrade package. Refer to Terraform Cloud pricing for details.
In addition to using existing technology partners integrations, HashiCorp Terraform Cloud customers can build their own custom run task integrations. Custom integrations have access to plan details in between the plan and apply phase, and can display custom messages within the run pipeline as well as prevent a run from continuing to the apply phase.
Prerequisites
To build a custom integration, you must have a server capable of receiving requests from Terraform Cloud and responding with a status update to a supplied callback URL. When creating a run task, you supply an endpoint url to receive the hook. We send a test POST to the supplied URL, and it must respond with a 200 for the run task to be created.
This feature relies heavily on the proper parsing of plan JSON output. When sending this output to an external system, be certain that system can properly interpret the information provided.
Available Run Tasks
You can view the most up-to-date list of run tasks in the Terraform Registry.
Integration Details
When a run reaches the appropriate phase and a run task is triggered, the supplied URL will receive details about the run in a payload similar to the one below. The server receiving the run task should respond 200 OK
, or Terraform will retry to trigger the run task.
Refer to the Run Task Integration API for the exact payload specification.
Once your server receives this payload, Terraform Cloud expects you to callback to the supplied task_result_callback_url
using the access_token
as an Authentication Header with a jsonapi payload of the form:
Refer to the Run Task Integration API for the exact callback specification.
Terraform Cloud expects this callback within 10 minutes, or the task will be considered to have errored
. The supplied message attribute will be displayed in Terraform Cloud on the run details page. The status can be passed
or failed
.
Here's what the data flow looks like:
Securing your Run Task
When creating your run task, you can supply an HMAC key which Terraform Cloud will use to create a signature of the payload in the X-Tfc-Task-Signature
header when calling your service.
The signature is a sha512 sum of the webhook body using the provided HMAC key. The generation of the signature depends on your implementation, however an example of how to generate a signature in bash is provided below.
HCP Packer Run Task
Hands On: Try the Set Up Terraform Cloud Run Task for HCP Packer, Standard tier run task image validation, and Plus tier run task image validation tutorials to set up and test the Terraform Cloud Run Task integration end to end.
Packer lets you create identical machine images for multiple platforms from a single source template. The HCP Packer registry lets you track golden images, designate images for test and production environments, and query images to use in Packer and Terraform configurations.
The HCP Packer validation run task checks the image artifacts within a Terraform configuration. If the configuration references images marked as unusable (revoked), the run task fails and provides an error message containing the number of revoked artifacts and whether HCP Packer has metadata for newer versions. For HCP Packer Plus registries, run tasks also help you identify hardcoded and untracked images that may not meet security and compliance requirements.
To get started, create an HCP Packer account and follow the instructions in the HCP Packer Run Task documentation.