Requirements
Git

Git Basics: Essential Skills for Your Terraform Journey

Before we dive into Terraform, let's ensure you're comfortable with Git. This version control system will be crucial for managing your infrastructure code and collaborating with others.

1. Creating a New Repository

Git allows you to track changes in your code over time. Let's start by creating a new repository:

  1. Navigate to GitHub (opens in a new tab) and log in or create a new account if you don't have one.
  2. Click the + icon in the top-right corner and select New repository.
  3. Name your repository (e.g., terraform-training).
  4. Choose Public visibility.
⚠️

Important: Do not commit any sensitive data to the repository as a best practice whether it is Public or Private.

  1. Check Add a README file.
  2. Under Add .gitignore select Terraform
  3. Click Create repository.

Creating a new GitHub repository

2. Setting Up SSH Keys

ℹ️

Note: If you are a Windows user, make sure to run the commands below in PowerShell, rather the Cmd Prompt. You do not need "Run as Administrator" unless specified

SSH keys provide a secure way to connect with GitHub:

  1. Open your terminal.

  2. Generate a new SSH key:

    ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/terraformclub

    At the "Enter passphrase" prompt you can leave it empty for no passphase.

  3. Add the keys to the ssh-agent:

    MacOS

    • Start the ssh-agent:
    eval "$(ssh-agent -s)"
    • Check to see if your ~/.ssh/config file exists in the default location.
    open ~/.ssh/config

    If the file doesn't exist, create the file.

    touch ~/.ssh/config
    • Open your ~/.ssh/config file, then modify the file to contain the following lines.
    config
    Host github.com
        AddKeysToAgent yes
        UseKeychain yes
        IdentityFile ~/.ssh/terraformclub

    Windows

    • Right-click Start Menu, select "Windows Powershell (Admin)"
    Set-Service -Name ssh-agent -StartupType Automatic
    Start-Service -Name ssh-agent
  4. Add your SSH key to the agent:

    ssh-add ~/.ssh/terraformclub
  5. Copy your public key:

    cat ~/.ssh/terraformclub.pub
  6. Go to GitHub Settings > SSH and GPG keys > New SSH key.

  7. Paste your key and save.

3. Cloning Your Repository

Now, let's get your repository on your local machine. Assuming your repository name is terraform-training:

git clone git@github.com:yourusername/terraform-training.git
cd terraform-training

4. Making Changes and Committing

As you work on your Terraform configurations, you'll need to commit your changes:

  1. Make some changes to your files.
  2. Stage your changes:
    git add .
  3. Commit your changes:
    git commit -m "Add initial Terraform configuration"
💡

Tip: Write clear, concise commit messages to document your work effectively.

5. Pushing Your Changes

Finally, let's push your local commits to GitHub:

git push origin main

Next Steps

Congratulations! You've mastered the Git basics needed for this course. Remember to commit and push your work for regularly. In the next section, we'll start exploring Terraform fundamentals.