Announcing Bitbucket Cloud Integration for Terraform Enterprise

Announcing Bitbucket Cloud Integration for Terraform Enterprise

Apr 19 2017    Mary Cutrali

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 Atlassian Bitbucket Cloud as a VCS integration with Terraform Enterprise. This post will discuss getting started with Terraform Enterprise and the first steps to setting up Bitbucket Cloud 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 integration with Bitbucket is part of Terraform Enterprise. Visit the Terraform Enterprise site to get started.

Registering Bitbucket Cloud and Terraform Enterprise

The first part will be to register Terraform Enterprise as an OAuth Application within your Bitbucket Cloud account. Proceed to https://bitbucket.org/account/user/your-username/oauth-consumers/new.

BB GIF 1

You will be redirected to https://bitbucket.org/account/user/your-username/api. Scroll down to OAuth Consumers and click on the application you just created. Copy the Key and Secret. Leave this tab open in your browser as you will need to return to it in a moment.

BB GIF 2

The second part will be creating a Terraform Enterprise OAuth Client. This will be done from the Terraform Enterprise UI. You will need the Key and Secret copied from Bitbucket site to complete this process.

BB GIF 3

Once you have created your client, you will be redirected back to the configurations page for your chosen organization. On that page, find the “OAuth Clients” pane and copy the Callback URL for your Bitbucket Cloud OAuth Client. In the open Bitbucket tab, select the Terraform Enterprise OAuth Application and click edit. Enter the Callback URL you just copied in the field labeled Redirect URI. Save the application.

BB GIF 4

Your OAuth Client should now be enabled for your Organization to use within Terraform Enterprise.

Using Bitbucket Cloud with Terraform Enterprise

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

BB GIF 5

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

BB GIF 6

You are now ready to use your organization's token to manage builds and configurations within Terraform Enterprise.

Connecting Terraform Enterprise and Packer to Bitbucket Cloud Repositories

Once you have linked a Bitbucket installation to your account or organization, you are ready to begin creating HashiCorp Packer Builds and Terraform Environments linked to your desired Bitbucket repository.

Using the Enterprise UI, the next part will connect a Bitbucket Cloud Repository to a Terraform Environment. From the Terraform Enterprise UI select ‘Link to Bitbucket Cloud’. 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.

BB GIF 7

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 Bitbucket. Once it completes 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, pull request, and merge.

Using the Enterprise UI, the next part will connect a Bitbucket Cloud 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 Bitbucket Cloud. 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.

BB GIF 8

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, pull request, and merge.

For complete documentation on the above process, refer to the VCS integration documentation for Bitbucket.

The emphasis of HashiCorp Terraform to codifying infrastructure provides a consistent approach to provision any infrastructure. This is particularly important for organizations adopting cloud or transitioning to a DevOps model 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 allows infrastructure to be described 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 version control system. To learn more about our Terraform Enterprise and request a free trial visit www.hashicorp.com/terraform.html.

close modal

Request a Demo

Fill out the form below and we'll reach out to discuss a product demo.

check mark
check mark
check mark
check mark
Select an option
  • Select one
  • Terraform
  • Nomad
  • Vault
  • Consul
Trusted by
  • Adobe Logo
  • Barclays Logo
  • Cisco Logo
  • Citadel Logo
  • DigitalOcean Logo
  • Hewlett Packard Enterprise Logo
  • SAP Arabia Logo
  • New Relic Logo
  • Pinterest Logo
  • Segment Logo
  • Spaceflight Logo
  • Stripe Logo