Connect to VCS Providers
HCP Terraform is more powerful when you integrate it with your version control system (VCS) provider. Although you can use many of HCP Terraform's features without one, a VCS connection provides additional features and improved workflows. In particular:
- When workspaces are linked to a VCS repository, HCP Terraform can automatically initiate Terraform runs when changes are committed to the specified branch.
- HCP Terraform makes code review easier by automatically predicting how pull requests will affect infrastructure.
- Publishing new versions of a private Terraform module is as easy as pushing a tag to the module's repository.
We recommend configuring VCS access when first setting up an organization, and you might need to add additional VCS providers later depending on how your organization grows.
Configuring a new VCS provider requires permission to manage VCS settings for the organization. (More about permissions.)
Supported VCS Providers
HCP Terraform supports the following VCS providers:
- GitHub App for TFE
- GitHub.com (OAuth)
- GitHub Enterprise
- GitLab.com
- GitLab EE and CE
- Bitbucket Cloud
- Bitbucket Data Center
- Azure DevOps Server
- Azure DevOps Services
Use the links above to see details on configuring VCS access for each supported provider. If you use another VCS that is not supported, you can build an integration via the API-driven run workflow.
How HCP Terraform Uses VCS Access
Most workspaces in HCP Terraform are associated with a VCS repository, which provides Terraform configurations for that workspace. To find out which repos are available, access their contents, and create webhooks, HCP Terraform needs access to your VCS provider.
Although HCP Terraform's API lets you create workspaces and push configurations to them without a VCS connection, the primary workflow expects every workspace to be backed by a repository.
To use configurations from VCS, HCP Terraform needs to do several things:
- Access a list of repositories, to let you search for repos when creating new workspaces.
- Register webhooks with your VCS provider, to get notified of new commits to a chosen branch.
- Download the contents of a repository at a specific commit in order to run Terraform with that code.
Important: HCP Terraform usually performs VCS actions using a designated VCS user account, but it has no other knowledge about your VCS's authorization controls and does not associate HCP Terraform user accounts with VCS user accounts. This means HCP Terraform's VCS user might have a different level of access to repositories than any given HCP Terraform user. Keep this in mind when selecting a VCS user, as it may affect your security posture in one or both systems.
Webhooks
HCP Terraform uses webhooks to monitor new commits and pull requests.
- When someone adds new commits to a branch, any HCP Terraform workspaces based on that branch will begin a Terraform run. Usually a user must inspect the plan output and approve an apply, but you can also enable automatic applies on a per-workspace basis. You can prevent automatic runs by locking a workspace. A run will only occur if the workspace has not previously processed a run for the commit SHA.
- When someone submits a pull request/merge request to a branch, any HCP Terraform workspaces based on that branch will perform a speculative plan with the contents of the request and links to the results on the PR's page. This helps you avoid merging PRs that cause plan failures.
Important: In Terraform Enterprise, integration with a SaaS VCS provider (GitHub.com, GitLab.com, Bitbucket Cloud, or Azure DevOps Services) requires ingress from the public internet. This lets the inbound web hooks reach Terraform Enterprise. You should also configure appropriate security controls, such as a Web Application Firewall (WAF).
SSH Keys
For most supported VCS providers, HCP Terraform does not need an SSH key. This is because Terraform can do everything it needs with the provider's API and an OAuth token. The exceptions are Azure DevOps Server and Bitbucket Data Center, which require an SSH key for downloading repository contents. Refer to the setup instructions for Azure DevOps Server and Bitbucket Data Center for details.
For other VCS providers, most organizations will not need to add an SSH private 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.
For VCS providers where adding an SSH private key is optional, SSH will only be used to clone Git submodules. All other Git operations will still use HTTPS.
If submodules will be cloned via SSH from a private VCS instance, SSH must be running on the standard port 22 on the VCS server.
To add an SSH key to a VCS connection, finish configuring OAuth in the organization settings, and then use the "add a private SSH key" link on the VCS Provider settings page to add a private key that has access to the submodule repositories. When setting up a workspace, if submodules are required, select "Include submodules on clone". More at Workspace settings.
Multiple VCS Connections
If your infrastructure code is spread across multiple VCS providers, you can configure multiple VCS connections. You can choose which VCS connection to use whenever you create a new workspace.
Scoping VCS Connections using Projects
You can configure which projects can use repositories from a VCS connection. By default each VCS connection is enabled for all workspaces in the organization. If you need to limit which projects can use repositories from a given VCS connection, you can change this setting to enable the connection for only workspaces in the selected projects.
Configuring VCS Access
HCP Terraform uses the OAuth protocol to authenticate with VCS providers.
Important: Even if you've used OAuth before, read the instructions carefully. Since HCP Terraform's security model treats each organization as a separate OAuth application, we authenticate with OAuth's developer workflow, which is more complex than the standard user workflow.
The exact steps to authenticate are different for each VCS provider, but they follow this general order:
On your VCS | On HCP Terraform |
---|---|
Register your HCP Terraform organization as a new app. Get ID and key. | Â |
 | Tell HCP Terraform how to reach VCS, and provide ID and key. Get callback URL. |
Provide callback URL. | Â |
 | Request VCS access. |
Approve access request. | Â |
For complete details, click the link for your VCS provider:
- GitHub
- GitHub Enterprise
- GitLab.com
- GitLab EE and CE
- Bitbucket Cloud
- Bitbucket Data Center
- Azure DevOps Server
- Azure DevOps Services
Note: Alternatively, you can skip the OAuth configuration process and authenticate with a personal access token. This requires using HCP Terraform's API. For details, see the OAuth Clients API page.
Private VCS
You can use self-hosted HCP Terraform Agents to connect HCP Terraform to your private VCS provider, such as GitHub Enterprise, GitLab Enterprise, and BitBucket Data Center. For more information, refer to Connect to Private VCS Providers.
Viewing events
VCS events describe changes within your organization for VCS-related actions. The VCS events page only displays events from previously processed commits in the past 30 days. The VCS page indicates previously processed commits with the message, "Processing skipped for duplicate commit SHA"
.
Viewing VCS events requires permission to manage VCS settings for the organization. (More about permissions.)
To view VCS events for your organization, go to your organization's settings and click Events. The VCS Events page appears.