VCS (Gitops) Driven Workspace

In this tutorial, we are going through step by step how to set up Scalr with a VCS driven workflow. This means storing your Terraform configuration in a version control system, such as Git, and having Scalr automatically perform actions when new code is being pushed.

Getting Started

The requirement for a VCS driven workspace is, obviously, having access to a version control system. We will be using a free Github.com account throughout this tutorial, but you can also use other providers, such as Gitlab, Azure Devops, or Bitbucket.

Adding Github credentials to Scalr

Select VCS Providers in the Scalr menu:

../_images/vcs_menu.png

Click on New VCS Provider button:

../_images/vcs_list.png

Enter a custom name for your new provider and make sure to copy the callback URL. You will need this URL when setting up authentication at Github.com. Now, click on the Register OAuth Application button to open Github.com in a new browser tab.

../_images/vcs_form.png

If you are not already logged in to Github, please do so. You will now be greeted with the registration form. As Application name, it’s recommended to enter Scalr + the name that you gave your provider at Scalr. This way, you will easily recognize where this registration is connected to in the future. Under Homepage URL, you should enter the base URL of your Scalr installation. Please paste the Callback URL that you copied in the previous step in the field Authorization callback URL. Now click on Register application.

../_images/vcs_github_form.png

Now Scalr has been registered with Github. But before Scalr is able to communicate with the Github API, we need to generate an API Secret Key. Click on the button Generate a new client secret. Github will ask you to confirm your password.

../_images/vcs_github_settings.png

Copy and paste the Client ID and the Client Secret to Scalr. Click on Create.

../_images/vcs_github_secret.png ../_images/vcs_form_filled.png

Github will now ask you for permission to authorize Scalr to access Github API on your behalf. Click Authorize.

../_images/vcs_github_authorize.png

Registration is now complete and we can see that the new provider has been added in Scalr.

../_images/vcs_providers_list.png

Create Workspace

Now when we have registered our VCS with Scalr, we are ready to create a VCS Workspace. Click on Workspaces in the Scalr menu.

../_images/vcs_menu_workspace.png

Click on New Workspace

../_images/vcs_workspaces.png

Give your workspace a name and make sure to select VCS provider as your configuration source. Now pick the VCS provider that we created in previous steps and select a repository that you want to be connected to your workspace. Click on Create.

If you don’t have any repository yet, please follow this guide on Github.com: https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository

../_images/vcs_workspace_form.png

Done! Now your workspace is configured and ready to rock!

../_images/vcs_workspace_idle.png

Test Run

Final step is to do a test-push to your repository to make sure Scalr actually picks it up. Go to your new repository on Github.com, click on the Add file dropdown and pick Create new file.

../_images/vcs_github_newfile.png

Name the file main.tf and type the following as file contents:

output "hello_world" {
      value = "Hello, World!"
}

Click on Commit new file.

../_images/vcs_github_helloworld.png

When going back to Scalr, you should now see that Scalr picked up the new changes and entered into a Planning state.

If you are interested in a bit more advanced setup with separate development and production workspaces with VCS integration, please watch this video: https://www.youtube.com/watch?v=pxZGsMnIqfg&t=1s&ab_channel=ScalrInc