2. Cloud Resume Challenge: GitHub and GitHub Actions

2. Cloud Resume Challenge: GitHub and GitHub Actions

To get started within this module, you will be creating a GitHub repo from the template repo. Then you will prepare your Terraform Cloud environment with some configurations in preparation for creating your AWS infrastructure.

Let's get started!


Cloning Template Repository

  • Login to GitHub

  • Go to my template > Select Use this template > Select Create a new repository

  • Input a Repo name and Description

  • Select Create repository


Cloning your repo

  • In your IDE terminal, clone your repository.
git clone https://github.com/YOUR_REPOSITORY.git PATH_TO_SAVE_LOCATION

  • Open the folder from your cloned repo


Create a New Branch in your repo

  • In GitHub, select Issues > New Issue

  • Enter a title for your issue, e.g. Modify GitHub Actions

  • Enter a description if you'd like

  • Select Submit new issue

  • On the right hand pane, under Development, select Create a branch

  • Leave the defaults and select Create branch

  • Open your IDE Terminal.

  • Input the following:

git fetch origin
git checkout YOUR_BRANCH_NAME


Configure Terraform Cloud

  • Login to Terraform

  • Select Projects & workspaces > Select New > Project

  • Input your Project Name

  • Select New > Workspace

  • Select API-Driven Workflow

  • Input your Workspace Name

  • Select the Project you created from the drop-down

  • Select Create

You will be taken to the Overview page for this workspace. You will see some Example code on this page with your organization and workspace name.

Take note of these.

  • On the left pane, Select Settings

  • Under the General section, scroll down and find the Terraform Working Directory
./infra

  • Save your change at the bottom

Creating Variables

  • Go back to the Overview page, select Variables

  • Create the following variables:

    • AWS_ACCESS_KEY_ID - Select the Sensitive dialog box

      • Select Add variable
    • AWS_SECRET_ACCESS_KEY - Select the Sensitive dialog box

      • Select Add variable


Creating Terraform API Token

  • At the top of the left pane, select your profile drop-down > Select Account Settings

  • Under Account Settings, Select Tokens

  • Select Create an API Token

  • Enter a name/description of the token and set an expiration date for it

  • Select Generate Token

Take note of the output from the token. You will need this for your GitHub Secrets


Add GitHub Secrets

  • Go back to GitHub

  • Select your repo for this project

  • Select Settings on the top right

  • On the left pane under Security, Select Secrets and variables > Actions

  • Select New repository secret

  • Create the following Secrets:

    • AWS_ACCESS_KEY_ID - same information as the Terraform Cloud Variable.

    • AWS_SECRET_ACCESS_KEY - same information as the Terraform Cloud Variable.

    • TF_API_TOKEN - output from Terraform Cloud API Token.

NOTE: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY will be utilized later for CloudFront invalidations.


Update .yml files

  • Open your IDE

  • Update your terraform-plan.yml and terraform-apply_cloudfront-invalidation.yml files to reflect your Organization and Workspace.

  • Save your files

Update ./infra/providers.tf

  • Update your providers.tf to include your organization, workspace and AWS region.

  • Save the file

Pushing to GitHub

  • Ensure your files are saved.

  • In your IDE Terminal, type the following:

git add .

Add all files that were changed.


git commit -m "updated .yml files with terraform organization and workspace."

Commit the changes with a comment.

git push

Push to GitHub.


Create Pull Request

  • Go to GitHub

  • You should see the push on your repository

  • Select Compare & pull request

  • Validate the changes that were made to be pushed to main

  • Select Create pull request

  • Select Merge pull request

  • Confirm merge

  • Delete Branch

  • In your IDE Terminal, input the following:

git checkout main

This will checkout main and swap out of your branch

git pull

This will pull the configuration from GitHub so that main is in sync


In the next module, you modify some of your terraform files to create an Amazon S3 Bucket. You'll also make modifications again to your GitHub workflow so that your resources will be created automatically.