VCS Workflow: Connect to VCS
Terraspace supports automating most of the VCS connection setup for your workspaces.
Prerequisite: VCS Provider OAuth Token
As a prerequisite, set up a VCS Provider. Follow the Terraform Docs: Configuring OAuth Access. Once done, you’ll see something like this:
From here, you can grab the OAuth Token ID.
Configure VCS Connection
To connect VCS to your workspace, configure the config.tfc.workspace.attrs
settings:
config/app.rb:
Terraspace.configure do |config|
# ...
vcs_repo = {
"identifier": "org/repo",
"oauth-token-id": 'token-id',
"ingress-submodules": true,
"branch": "master",
}
config.tfc.workspace.attrs['vcs-repo'] = vcs_repo
end
Deploy
Then deploy:
terraspace up demo
Terraspace automatically updates the TFC Workspace and with the repo connection as part of the terraspace up
command.
Sync
You can also configure the VCS connection without deploying. To do so, use:
terraspace tfc sync demo
This syncs the Terraspace project settings to Terraform Cloud. A sync performs the following for each workspace:
- Create or update workspace, including the VCS settings.
- Set the working dir. This is automatically determined. Though you can adjust the working_dir_prefix.
- Set env and terraform variables. The variables can be configured with code. See Cloud Vars.
Sync All & Preview
You can sync all the workspaces. This can be useful, if your TFC user does not have permission to manage workspaces. You can ask the TFC admin to run the sync command to create the workspaces in batch. Example:
$ terraspace tfc sync # all workspaces
About to sync these project stacks with Terraform Cloud workspaces:
Stack => Workspace
demo => demo-dev-us-west-2
demo2 => demo2-dev-us-west-2
A sync does the following for each workspace:
1. Create or update workspace, including the VCS settings.
2. Set the working dir.
3. Set env and terraform variables.
Are you sure? (y/N)
If you would like to bypass the prompt, you can use the -y
option.
terraspace tfc sync -y
Disconnect VCS
TFC maintains previous settings if the config is not set. If you need to disconnect the workspace from VCS, set vcs-repo
to nil
. Example:
Terraspace.configure do |config|
# ...
config.tfc.workspace.attrs['vcs-repo'] = nil
end
Manual Setup
If you need to set up the VCS connection manually instead, see Connect to VCS Manually.