Announcing Terraform Enterprise Integration for GitLab

HashiCorp Terraform enables users to define infrastructure as code to safely and predictably codify, plan, and provision any infrastructure. Terraform can provision public cloud resources, private cloud resources, as well as service provider resources like DNS and monitoring to provide a consistent workflow for provisioning.

HashiCorp Terraform Enterprise provides integration with version control systems (VCS) to facilitate collaboration on infrastructure as code. Terraform Enterprise users have been doing version-controlled infrastructure with GitHub and Terraform Enterprise. We are excited to announce the addition of GitLab as a VCS integration with Terraform Enterprise. This post will discuss getting started with Terraform Enterprise and the first steps to setting up GitLab for your environment.

»Getting Started with Terraform Enterprise

The Terraform CLI works great for individuals, hobby projects, and small teams, but like most CLI tools, it tends to not scale well without a centralized coordination system. The goal of Terraform Enterprise is to simplify using and coordinating Terraform in a team setting. The integrations with version control system such as GitLab are part of Terraform Enterprise. Visit the Terraform Enterprise site to get started.

»Registering GitLab and Terraform Enterprise

The first part will be to register Terraform Enterprise as an OAuth Application within your GitLab account. GitLab 1

Once you save the form, you will be redirected to the OAuth Application view. Copy your Application Key and Secret as you will need them to connect GitLab to Terraform Enterprise.

The next part will be inputting your GitLab Application Key and Secret into the Terraform Enterprise UI. GitLab 2

From the Terraform Enterprise UI, you will copy the Callback URL for your GitLab OAuth Client. Then on GitLab, select the terraform-enterprise OAuth Application. Enter the Callback URL in the field labeled Redirect URI
GL GIF 3

»Using GitLab with Terraform Enterprise

To use Terraform Enterprise with GitLab you will need to link to a Terraform Enterprise organization. During the authorization process, there will be a brief redirect to GitLab, from the Terraform Enterprise UI, in order to authenticate the client.

GL GIF 4

The next part will be to link the Terraform Enterprise User Account. During this authorization process, there will be a redirect to GitLab in order to authenticate your OAuth Client.

GL GIF5

»Connecting Terraform Enterprise and Packer to GitLab Repositories

In this section you will begin creating HashiCorp Packer Builds and Terraform Environments that are linked to your desired GitLab Repository.

Using the Enterprise UI, you will connect a GitLab Repository to a Terraform Environment. A Menu will appear asking you to name the environment. Then use the autocomplete field for repository and select the repository for which you'd like to create a webhook & environment. If necessary, fill out information about the VCS branch to pull from as well as the directory where the Terraform files live within the repository. Click Create and Continue.

GL GIF 6

Upon success, you will be redirected to the environment's runs page. A message will display letting you know that the repository is ingressing from GitLab. When it competes you will be able to Queue, Run, & Apply a Terraform Plan. Depending on your webhook settings, changes will be triggered through git events on the specified branch. The events currently supported are repository and branch push, merge request, and merge.

Using the Enterprise UI, the next part will connect a GitLab Repository to a Packer build configuration. Select the organization for which you'd like to create a build configuration. Name your build & select Connect build configuration to a Git Repository. A form will appear asking you to select your Git Host. Select your preferred GitLab integration. Choose the repository for which you'd like to create a webhook. Fill out any other information in the form such as preferred branch to build from (your default branch will be selected should this field be left blank), Packer directory, and Packer Template.

GL Gif 7

Upon clicking Create you will be redirected to the build configuration. On this page, you will have the opportunity to make any changes to your Packer template, push changes via the CLI, or manually queue a Packer build. Depending on your webhook settings, changes will be triggered through git events on the specified branch. The events currently supported are repository and branch push, merge request, and merge.

For complete documentation of the above process, refer to the VCS integration documentation for GitLab.

HashiCorp Terraform provides a consistent approach to provision any infrastructure. This is particularly important for organizations adopting cloud or transitioning to DevOps for application delivery. Consider a resource group on AWS compared to a set of Virtual Machines on Azure. Or a pool of servers on GCP compared to Virtual Machines on vSphere. Conceptually they are all the same and provide infrastructure. The work required to provision and manage them is actually a bit different. Terraform describes infrastructure using a common template in a high-level configuration syntax. The configuration file is then versioned and treated as you would any other code using a VCS. To learn more about our Terraform Enterprise or request a free trial visit www.hashicorp.com/terraform.

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.