Intro

In my last couple of posts, I have been building an AWS static site with Terraform and Terraform Cloud. In this post, I will show you how to connect your Terraform Cloud Workspace to a GitHub repo (that contains the Terraform code from the previous post). I will also configure the workspace to deploy the site automatically when there is push to the main branch of the repo.

Note
The Terraform code used to deploy the site can be found here.

Ok peeps! You ready to rock? Let's Party on Wayne 🤘

Workspace Settings

The first step is enabling the Terraform Workspace for remote execution. Browse to:

Then ensure that the Excution Mode is set to Remote and click Save settings.

Enable VCS

Next up, set the workspace up for Version Controlled Workflow. Browse to:

Click on GitHub then select GitHub.com.

In the pop-up click Authorize Terraform Cloud.

blog/terraform-cloud-version-controlled-workflows-with-github/authorize.png

Select the GitHub organization to install the Terraform Cloud app into.

blog/terraform-cloud-version-controlled-workflows-with-github/organization.png

I am enabling the app for Only selected repositories and only for the aws-static-site-tf repo.

blog/terraform-cloud-version-controlled-workflows-with-github/select-repo-1.png

Click Install once you have finished selecting repos.

Now, back on Terraform Cloud select the aws-static-site-tf repo to go to the settings page.

blog/terraform-cloud-version-controlled-workflows-with-github/select-repo-2.png

Set the Apply Method to Auto apply. Also, set the VCS branch to main then click Update VCS settings.

With this configuration in place, any push to the main branch of the repo will trigger a terraform apply -auto-approve run on Terraform Cloud, and the infrastructure defined in your Terraform code will be deployed automagically 🎸

Outro

Thanks for tuning in. In this post, I covered the process to connect your Terraform Cloud environment to a GitHub repo and automatically deploy infrastructure to AWS when there is a push to the main branch of the repo.

Devops Borat would be so proud.