Tutorial - Setting up Terraform Cloud with Github

Tutorial - Setting up Terraform Cloud with Github

In this tutorial, we are going to configure a Terraform Cloud account with Github and will be creating a few EC2 instances. This tutorial is not to explain how terraform works or its concepts. This is just to show you how terraform cloud can be configured with Github.


  1. Github Account
  2. AWS Account ( Basic understanding about How to create new IAM User and assign permissions)
  3. Basic knowledge about Terraform

Step 1: Create Terraform Cloud Account

As of now, Terraform is offering below pricing models for account

  1. Free
  2. Team & Governance
  3. Business

In this tutorial, we will be using a Free account.

Create a new account using this link - Once the account is created, confirm the provided email address.

On the welcome screen, click on “Not right now, skip questions”.

Step 2: Create a new organization

Organizations are common space for the teams to collaborate on infrastructure. Refer this link to learn more about organization

  1. Enter organization name and email id
  2. Click on “Create organization”


Step 3: Create a new Workspace

Once an organization is created, you will be navigated to the next step that is “Create a new Workspace”.

if you are familiar with terraform workspaces then you might know that we can create workspaces to organizes cloud infrastructures. For example, You can create a separate cloud infrastructure for Development, Test, and Prod environment.

below workflows can be used to create workspaces,

  • Version Control such as Github, Gitlab, BitBucket and Azure DevOps

  • CLI Driven

  • API Driven

before creating a new workspace, let’s configure a VCS provider.

Step 4: Configure a VCS provider


  1. For that, Navigate to Settings > VCS Providers
  2. Click on “Add a VPC provider”
  3. Select GitHub > (Custom)

Now let’s follow the steps mentioned on the “Set up provider” page.


  1. Goto > On GitHub, register a new OAuth Application. Refer this link

  2. Populate Application Name, Homepage URL, and Authorization callback URL as given by terraform. Click on “Register Application”.


  1. Once the application is registered on you will be provided Client ID and Secret Key. Go back to Terrform page and enter Name as “”. Populate Client ID and Secret key provided by


  1. Click on “Connect and Continue”

  2. Authorize Terraform Cloud (your_application_name) on


You will be navigated to the “Set up SSH keypair (optional)” page, lets skip this step as it is optional.

Step 5: Create a GitHub repo

Create a GitHub repository. This repo will be used to save all terraform configurations files for Development env.

For this demo, we will using this repository


As of now, keep the repository empty. In the next steps, we will add some terraform infrastructure files.

Step 6: Continue step 3 > create workspace

  1. Go back to Terraform and navigate to the “Workspaces” Tab.
  2. Click on “New Workspace”
  3. Choose your workflow = Version control workflow
  4. Connect to a version control provider = Github
  5. Choose a repository = <your_repository name> in this case, it would be > claim-demo-app-dev
  6. Click on “Create Workspace”

Wait for the configuration check, once that is done you would be provided this message “Configuration uploaded successfully”


Step 7: Configure Variables

let’s add below AWS environment variables so that we can spin up some EC2 instances.



Note: To get aws_access and secret_key, Login to AWS Account.

Go to IAM > users > [[your_user_name]] > Security Credentials

IMPORTANT: Make sure that IAM user has Programmatic access and AdministratorAccess permissions.


Step 8: Spin up some EC2 instances

So far we have configured GitHub and created a workspace for our development environment. Now let’s create some EC2 instance using terraform.

  1. Go to > [[you_repo]]

  2. Create a file with the below code. Make sure that the file extension

  1. Go back to terraform > workspaces > [[select your workspace]] in this case = claim-demo-app-dev

  2. Click on the “Queue plan” list and enter some comment and click “Queue Plan”. A new job would be triggered once you click on the “Queue plan” button.

  3. When the job at “NEEDS CONFIRMATION”, check all the infrastructure configuration and Click on “Confirm and Apply”


Step 9: Validate EC2 Instance

Once the above step is completed, login to the AWS account and verify EC2.



Now whenever GitHub code is updated, a new job would be triggered at terraform automatically. Those jobs can be viewed from the Workspaces > App > Runs tab.


So go ahead and try some.

Step 10: Destroy created infrastructure

  1. To destroy infrastructure, navigate to workspace > app > Settings > Destruction and Deletion

  2. Click on “Queue destroy plan” button

  3. Enter the workspace and confirm

I hope you liked this blog and got a good understanding of Terraform Cloud Setup with Github. If you are facing any issue while implementing this then reach out to me or refer this terraform troubleshooting page.