» Run Tasks

Run Tasks allow you to directly integrate third-party tools and services at certain stages in the Terraform Cloud run lifecycle. When triggered, a run task sends an API payload to the external service. This payload contains a collection of run-related information, including a callback URL that the service uses to respond back to Terraform Cloud with a passed or failed status. Terraform Cloud uses this status response to determine if a run should proceed, based on the run task's enforcement settings that have been configured for the workspace.

You can manage run tasks through the UI as detailed below or through the Run Tasks APIs.

» Requirements

Terraform Version - You can only assign run tasks to workspaces that use a Terraform version of 0.12 and later. Downgrading a workspace with existing run tasks to use a prior Terraform version will not result in an error, but Terraform Cloud will no longer trigger the run tasks during plan and apply operations.

Permissions - To create a run task, you must have a user account with organization owner permissions. To associate run tasks to a workspace, you must be at least a workspace administrator.

» Creating a Run Task

To create a new run task:

  1. Navigate to the desired workspace, open the Settings menu and select Run Tasks.

    Screenshot: a workspace's settings drop-down menu

  2. Click Create a new run task. The Run Tasks page appears.

  3. Click Create run task.

    Screenshot: an organization's blank run tasks state

  4. Enter the information about the run task to be configured:

    • Name (required): A human-readable name for the run task. This will be displayed in workspace configuration pages and can contain letters, numbers, dashes and underscores.
    • Endpoint URL (required): The URL for the external service. Run tasks will POST the run tasks payload to this URL.
    • HMAC key (optional): A secret key that may be required by the external service to verify request authenticity.
  5. Click Create run task.

    Screenshot: an organization's populated run tasks state

» Adding Run Tasks to a Workspace

  1. Click Workspaces in the top navigation bar, click your workspace in the grid, open the Settings menu and select Run Tasks.

  2. Click the + next to the task(s) you want to add to the workspace.

    Screenshot: a workspace's populated tasks configuration page

  3. Choose an enforcement level:

    • Advisory - Run tasks can not block a run from completing. If the task fails, the run will proceed with a warning in the UI.
    • Mandatory - Run tasks can block a run from completing. If the task fails (including a timeout or unexpected remote error condition), the run will transition to an Errored state with a warning in the UI.
  4. Click Create. Your run task is now configured. Screenshot: enforcement configuration for a specific task within a workspace

    Screenshot: final configuration of tasks within a workspace

» Understanding Run Tasks Within a Run

Run tasks perform actions between the plan and apply stages of a Terraform run. Once all run tasks have completed, the run will end based on the most restrictive enforcement level in each associated run task.

For example, if a mandatory task fails and an advisory task succeeds, the run will fail. If an advisory task fails, but a mandatory task succeeds, the run will succeed and proceed to the apply stage. Regardless of the exit status of a task, Terraform Cloud displays the status and any related message data in the UI.

Here is an example of a run that failed due to a mandatory run task.

Screenshot: a run with failed tasks

And here is an example of a run that succeeded.

Screenshot: a run with passed tasks

» Removing a Run Task from a Workspace

Removing a run task from a workspace does not delete it from the organization. To remove a run task from a specific workspace:

  1. Navigate to the desired workspace, open the Settings menu and select Run Tasks.

  2. Click the ellipses (...) on the associated run task, and then click Remove. The run task will no longer be applied to runs within the workspace.

    Screenshot: removing a run task from a workspace

» Deleting a Run Task

You must remove a run task from all associated workspaces before you can delete it. To delete a run task:

  1. Navigate to Settings in the top navigation bar and click Run Tasks.

  2. Click the ellipses (...) next to the run task you want to delete, and then click Edit.

  3. Click Delete run task.

You cannot delete run tasks that are still associated with a workspace. If you attempt this, you will see a warning in the UI containing a list of all workspaces that are associated with the run task.

Screenshot: a warning when attempting to delete an in-use run task