Skip to main content
All CollectionsIntegrate Everything
HashiCorp Terraform Cloud
HashiCorp Terraform Cloud

Manage resources in Torq with Terraform Cloud integration: Automate workflows, estimate costs, handle OAuth, and more.

Updated over 6 months ago

The HashiCorp Terraform integration enables you to manage your primary resources directly from Torq workflows.

  • Accounts

  • Cost estimates

  • OAuth clients

  • Organizations

  • Runs

  • Subscriptions

  • Variables

  • Workspaces

  • Workspace notifications

Use Terraform Cloud Steps in a Workflow

Get your Terraform API token

Depending on how you want to interact with Terraform in Torq, you need to generate and use the proper API token. Torq tested and verified that all Terraform steps in Torq can be run with a User token.

  • User tokens: each Terraform Cloud user can have any number of API tokens, which can make requests on their behalf.

  • Team tokens: each team can have one API token at a time. This is intended for performing plans and applies via a CI/CD pipeline.

  • Organization tokens: each organization can have one API token at a time. This is intended to automate the management of teams, team membership, and workspaces. The organization token cannot perform plans and applies.

User Token

  1. Click your user avatar/user photo.

  2. Select User Settings.

  3. Go to Tokens.

  4. Click the Create an API token button.

    image.png
  5. Give the token a meaningful description, such as, Token for Torq workflows and click Create API token.

    image.png

Team Token

  1. Go to the organization where the team exists.

  2. Click Settings and go to Teams.

  3. Click the Create a team token button.

    image.png
  4. Copy the token and save it. It will not be displayed again.

    image.png

Organization Token

  1. Go to the organization.

  2. Click Settings > API tokens.

  3. Click the Create an organization token button.

    image.png
  4. Copy the token and save it. It will not be displayed again.

    image.png

Create a Terraform Clouds Steps Integration in Torq

The integration stores the API token. The integration is used to authenticate Terraform steps in a workflow.

  1. Go to Build > Integrations > Steps > HashiCorp Terraform and click Add.

  2. Give the integration a meaningful name.

  3. Paste the API key you created earlier.

Use Run Tasks to Trigger Torq Workflows

You can trigger Torq workflows with events from Terraform using run tasks.

Create a Terraform Cloud trigger integration in Torq

The integration generates a unique endpoint URL in Torq. You'll use this URL as the Webhook URL when you create a run task or notification in Terraform Cloud.

  1. Go to Integrations > Triggers > Terraform Cloud and click Add.

  2. Give the integration a meaningful name, for example, terraform-run-task or terraform-notification.

    image.png
  3. Copy the endpoint URL. You'll need this when creating a run task in Terraform Cloud.

Create a Run Task

Run tasks are created on the organization level and applied on the workflow level.

  1. In your Terraform Cloud instance, go to the appropriate organization and click Settings > Run tasks > Create run task.

    image.png
  2. Complete the Create a Run Task form and click Create run task.
    a. Name: a meaningful name for the run task, for example, torq-run-task.
    b. Endpoint URL: the Torq endpoint URL you created and copied earlier.
    c. Description (optional): explain what this run task is.

    image.png

Trigger a Workflow with a Run Task

At this point, you've created a Terraform Cloud trigger integration in Torq, which generated a unique endpoint in Torq. You then associated this endpoint with a run task in Terraform Cloud.

  1. In Torq, go to the Workflows page and click Create Workflow.

  2. Select the Integrations trigger, click the Terraform Cloud card, and select the integration you created.

  3. To send information back to the run task, add an HTTP Request step for each data item you want to send. If a callback is not performed within 10 minutes of the run task being triggered, the task will fail. Use all of the values below to configure the HTTP Request step. The BODY parameter will vary depending on the data you're sending back to the run task.

Premade Steps

These are the premade steps for Terraform Cloud. Don't see a step you need? No problem, you can easily create custom steps.

  • Apply run plan

  • Create organization

  • Create run plan

  • Create VCS workspace

  • Delete organization

  • Delete workspace

  • Get account details

  • Get subscription details

  • List OAuth clients

  • List organizations

  • List workspace notifications

  • List workspaces

  • List workspace variables

  • Run task callback

Did this answer your question?