Part 5: Terraform with Azure – Install Git and initialise repository

Reading Time: 6 minutes

My journey preparing to get started with learning Terraform to allow me to deploy workloads into Microsoft Azure continues. If you missed the previous posts, please visit the links below.

Part 1: Terraform with Azure – How to install Terraform
Part 2: Terraform with Azure – How to install Azure cli
Part 3: Terraform with Azure – How to Install Visual Studio Code
Part 4: Terraform with Azure – How to install Azure Terraform Plugin in Visual Studio Code

In this blog post I go through the process of installing Git, enabling in Visual Studio code and initialise a git repository.

Notes:
Git is a tool that allows you to create a local repository on your local machine and manages the versions of your files.

GitHub is a cloud hosted solution that will allow you to host your Git repository in the Cloud.

Visual Studio Code also known as VSCode is a code editor which allows users to develop, execute and debug code. There are a range of editor tools available. VS Code is one of the popular ones.

Note, the official Visual Studio Code website states,

VS Code will leverage your machine’s Git installation, so you need to install Git first before you get these features. Make sure you install at least version 2.0.0

However, if Git is not installed, we can still install the software for free from the Git website after the installation of Visual Studio Code.

  1. Visit the download page at Git – Downloads (git-scm.com)

At the time of writing this blog post, the latest version of Git for Windows was 2.35.1

2. I’m using a Windows Operating system, therefore the website detects this automatically and displays a download for Windows. Click ‘Download for Windows’

3. Click here to download

4. After download, run the .exe

5. When ready to continue with setup, click next

6. Click next

7. Click Additional icons, this option will add shortcuts to your desktop for easy access. Click Next

8. Click Next

9. We select the default editor. I’ll be selecting Use Visual Studio Code as Git’s default editor

10. Review and click next

11. Review and click next

12. Review and click next

13. Review and click next

14. Review and click next

15. Review and click next

16. Review and click next

17. Review and click next

18. Review and click next

19. Review and click install

20. and we’re done with the installation of Git. Click Finish

21. Launch the Git Bash shortcut available on your desktop

22. To confirm the version installed, type git –version

How to enable Git in Visual Studio Code (VSCode)

In the next part of this blog post, we will go through the process of enabling Git in VSCode

  1. Launch Visual Studio Code
  2. Click File > Preferences >> Settings

3. Type git enabled in the search bar, and if not already enabled select the check box Git: enabled

That’s VSCode configured to use Git.

Next we need to run some basic configuration to setup Git and create a folder for our Terraform project

4. Launch command prompt (cmd.exe) or use Git-bash and type the following commands, replace the fields with your name and email address.

git config –global user.email “you@example.com

git config –global user.name “Your Name

Now we’ll create a folder for our Terraform project and open the folder in Visual Studio Code.

5. Create a new Project folder on your local machine. For the purpose of this demo, I have created C:\Users\myusername\Projects\Blog-Terraform-Tutorial

6. Launch Visual Studio Code if not already open

7. Click File > Open Folder

8. Browse to the newly created folder and click select. My folder was named Blog-Terraform-Tutorial

9. In Visual Studio Code, click view and enable the option SCM (integrated source control management). Visual Studio Code has integrated source control management (SCM) and includes Git support out-of-the-box.

10. Click the option Initialise Repository

Git is now setup for your new project

11. A .git folder is created within your new project folder. .git is hidden by default due to this folder storing important git related information. However, there may be a requirement to access the folder. You can view the folder in explorer by clicking view and selecting hidden items.

12. The folder will remain hidden within Visual Studio Code by default. To make it visible, back in Visual Studio Code (VSCode) click File > Preferences > Settings and type exclude in the search box. Here is a list of folders hidden in VSCode.

13. Hover over the record **/.git and click the X to delete

14. If the .git folder does not appear, close and relaunch Visual Studio Code

Next, I create a git ignore text file in my local repository (Right click, click new file and name it .gitignore. We’ll be making use of this file later.

What is gitignore?
A gitignore file is a text file you create manually in your repository. The purpose of gitignore is to ensure that certain files which are not tracked by git remain untracked. In most coding projects you will have files that you don’t want to be included in version control, such as build, cache files, etc. Therefore, you can include these files in the .gitignore file which instructs git not to add these excluded files to version control. It’s recommended that a .gitignore file is created after the repository is created.

That’s it for now. I hope you found this blog post useful. Please feel free to comment below if you wish to share any tips.

In the next blog post, I go through the process of deploying the first resources in Azure using Terraform. Check out part 6 at the following link https://cloudbuild.co.uk/part-6-terraform-with-azure-deploy-resources-in-azure/