HashiCorp releases a new CI/CD pipeline integration tool and templates for Terraform Cloud

New CI/CD pipeline templates for GitHub Actions and GitLab CI provide prescriptive guides for integrating with Terraform Cloud, and a new integration tool can help build workflows with other CI/CD platforms.

HashiCorp is excited to announce the release of pipeline templates for Terraform Cloud and Terraform Enterprise. These templates come with a command line tool for prescriptively setting up and running a Terraform Cloud workflow within a CI/CD pipeline, reducing friction that can often occur in highly customized pipelines. The templates also provide prescriptive examples for other CI/CD platforms on how to integrate with Terraform Cloud.

This post introduces two new pipeline templates and offers some background on how these integrations work and the customer feedback that led to them.

»The need for a prescriptive approach to using Terraform with CI/CD

One request we often get from Terraform Cloud users is for prescriptive guidance on how to use Terraform Cloud in their CI/CD pipelines. In addition, we know that many of our partners who offer CI/CD platforms want to provide their users with prescriptive Terraform Cloud integration workflows from their side as well. While Terraform Cloud’s VCS workflows are the initial solution we recommend, many customers have existing CI/CD tooling in place and want to integrate Terraform Cloud into their custom pipelines.

For tricky integrations, users typically embed Terraform Cloud as a job within CI/CD workflows and use the CLI workflow within a CI/CD tool to execute plans and applies. This approach is simple to implement but does not provide all the capabilities of Terraform Cloud, such as saving cloud runs and a bi-directional link back from Terraform Cloud to the code. These features are available only via API workflows, but those workflows are also more complex to set up.

Terraform Cloud APIs represent the actions that are part of a run from Terraform Cloud’s perspective, such as packaging and uploading code, starting runs, and applying changes. These common actions are automatically executed as part of the CLI or VCS workflow, so they are harder to implement without more detailed knowledge of the Terraform Cloud APIs

»How the application and templates work

To reduce the friction of this integration process, we created a new CLI tool called tfci. It’s a Go application inside a Docker container that automates Terraform Cloud runs via API and supports common Terraform Cloud operations that can be embedded into any CI tool. This allows users to onboard Terraform Cloud into more complex CI/CD pipelines.

Along with tfci, we created a pair of initial pipeline templates that act as blueprints for integrating tfci into CI/CD platforms:

GitHub Actions and GitLab CI are the two most common platforms for which users requested prescriptive workflows. Our intention is for third parties to participate and also add additional workflows and CI/CD platforms over time. Note that tfci can still be used to integrate Terraform Cloud into any CI/CD platform. Pipeline templates simply make the process faster and easier. Also note that tfci works with current versions of Terraform Enterprise since it uses the same APIs.

A Terraform Cloud run executed from a GitHub Actions pipeline using the new template.

A Terraform Cloud run executed from a GitHub Actions pipeline using the new template.

»Final notes and next steps

HashiCorp has published tfci on our tfc-workflows-tooling GitHub repository. The CI/CD pipeline templates are located in these two repositories:

If you want a hands-on guide for setting up tfci-powered GitHub Actions workflows, follow our updated Automate Terraform with GitHub Actions tutorial.

In each repository you can find documentation and open pull requests or issues. If you have an idea or want to see something new, please let us know by getting in touch through these GitHub repos.

Sign up for the latest HashiCorp news

By submitting this form, you acknowledge and agree that HashiCorp will process your personal information in accordance with the Privacy Policy.