Set up the Bitbucket Cloud VCS provider
This topic describes how to connect Bitbucket Cloud to HCP Terraform. Bitbucket Cloud is the cloud-hosted version of Bitbucket. For self-hosted Bitbucket Data Center instances, refer to Configuring Bitbucket Data Center Access. Refer to Connecting VCS Providers to HCP Terraform for other supported VCS providers.
Configuring a new VCS provider requires permission to manage VCS settings for the organization. (More about permissions.)
Connecting HCP Terraform to your VCS involves four steps:
On your VCS | On HCP Terraform |
---|---|
 | Create a new connection in HCP Terraform. Get callback URL. |
Register your HCP Terraform organization as a new app. Provide callback URL. Get ID and key. | Â |
 | Provide HCP Terraform with ID and key. Request VCS access. |
Approve access request. | Â |
The rest of this page explains the Bitbucket Cloud-specific versions of these steps.
Step 1: On HCP Terraform, Begin Adding a New VCS Provider
Go to your organization's settings and then click Providers. The VCS Providers page appears.
Click Add VCS Provider. The VCS Providers page appears.
Select Bitbucket and then select Bitbucket Cloud from the menu. The page moves to the next step.
Leave the page open in a browser tab. In the next step you will copy values from this page, and in later steps you will continue configuring HCP Terraform.
Step 2: On Bitbucket Cloud, Create a New OAuth Consumer
In a new browser tab, open Bitbucket Cloud and log in as whichever account you want HCP Terraform to act as. For most organizations this should be a dedicated service user, but a personal account will also work.
Important: The account you use for connecting HCP Terraform must have admin access to any shared repositories of Terraform configurations, since creating webhooks requires admin permissions.
Navigate to Bitbucket's "Add OAuth Consumer" page.
This page is located at
https://bitbucket.org/<YOUR WORKSPACE NAME>/workspace/settings/oauth-consumers/new
. You can also reach it through Bitbucket's menus:- Click your profile picture and choose the workspace you want to access.
- Click "Settings".
- Click "OAuth consumers," which is in the "Apps and Features" section.
- On the OAuth settings page, click the "Add consumer" button.
This page has a form with several text fields and checkboxes.
Fill out the fields and checkboxes with the corresponding values currently displayed in your HCP Terraform browser tab. HCP Terraform lists the values in the order they appear, and includes controls for copying values to your clipboard.
Fill out the text fields as follows:
Field Value Name HCP Terraform ( <YOUR ORGANIZATION NAME>
)Description Any description of your choice. Callback URL https://app.terraform.io/<YOUR CALLBACK URL>
URL https://app.terraform.io
(or the URL of your Terraform Enterprise instance)Ensure that the "This is a private consumer" option is checked. Then, activate the following permissions checkboxes:
Permission type Permission level Account Write Repositories Admin Pull requests Write Webhooks Read and write Click the "Save" button, which returns you to the OAuth settings page.
Find your new OAuth consumer under the "OAuth Consumers" heading, and click its name to reveal its details.
Leave this page open in a browser tab. In the next step, you will copy and paste the unique Key and Secret.
Step 3: On HCP Terraform, Set up Your Provider
Enter the Key and Secret from the previous step, as well as an optional Name for this VCS connection.
Click "Connect and continue." This takes you to a page on Bitbucket Cloud asking whether you want to authorize the app.
Click the blue "Grant access" button to proceed.
Step 4: On HCP Terraform, Configure Advanced Settings (Optional)
The settings in this section are optional. The Advanced Settings you can configure are:
- Scope of VCS Provider - You can configure which workspaces can use repositories from this VCS provider. By default the All Projects option is selected, meaning this VCS provider is available to be used by all workspaces in the organization.
- Set up SSH Keypair - Most organizations will not need to add an SSH key. However, if the organization repositories include Git submodules that can only be accessed via SSH, an SSH key can be added along with the OAuth credentials. You can add or update the SSH key at a later time.
If You Don't Need to Configure Advanced Settings:
- Click the Skip and Finish button. This returns you to HCP Terraform's VCS Provider page, which now includes your new Bitbucket Cloud client.
If You Need to Limit the Scope of this VCS Provider:
Select the Selected Projects option and use the text field that appears to search for and select projects to enable. All current and future workspaces for any selected projects can use repositories from this VCS Provider.
Click the Update VCS Provider button to save your selections.
If You Do Need an SSH Keypair:
Important Notes
- SSH will only be used to clone Git submodules. All other Git operations will still use HTTPS.
- Do not use your personal SSH key to connect HCP Terraform and Bitbucket Cloud; generate a new one or use an existing key reserved for service access.
- In the following steps, you must provide HCP Terraform with the private key. Although HCP Terraform does not display the text of the key to users after it is entered, it retains it and will use it when authenticating to Bitbucket Cloud.
- Protect this private key carefully. It can push code to the repositories you use to manage your infrastructure. Take note of your organization's policies for protecting important credentials and be sure to follow them.
On a secure workstation, create an SSH keypair that HCP Terraform can use to connect to Bitbucket Cloud. The exact command depends on your OS, but is usually something like:
ssh-keygen -t rsa -m PEM -f "/Users/<NAME>/.ssh/service_terraform" -C "service_terraform_enterprise"
This creates aservice_terraform
file with the private key, and aservice_terraform.pub
file with the public key. This SSH key must have an empty passphrase. HCP Terraform cannot use SSH keys that require a passphrase.While logged into the Bitbucket Cloud account you want HCP Terraform to act as, navigate to the SSH Keys settings page, add a new SSH key and paste the value of the SSH public key you just created.
In HCP Terraform's Add VCS Provider page, paste the text of the SSH private key you just created, and click the Add SSH Key button.
Finished
At this point, Bitbucket Cloud access for HCP Terraform is fully configured, and you can create Terraform workspaces based on your organization's shared repositories.