Getting started with Azure and Terraform – Part 1

Martin Therkelsen/ May 3, 2021/ Automation, Azure, Citrix, DevOps, Microsoft/ 1 comments

In this series, I want to go through deploying a complete infrastructure in Azure using Terraform. My goal is to create a virtual network, network security groups, VPN to on-premises, a couple of virtual machines with Citrix Cloud connector installed on them. I am learning this myself as I go through this series, so if anyone reading this has some pointers to do it better or easier, please do reach out to me.

The first step for me is to get Terraform installed and set up to save the deployment states in my Azure Storage Account. The installation of Terraform is a straight forward as can be, I download the software here, and then I unpack the exe file. I create a new folder on my c-drive called Terraform and place the exe file in this folder. I then add c:\Terraform to my path variable in Windows. Below is the setup I created.

Next, I need to install the Azure CLI since Terraform uses this to connect to Azure. Azure CLI can be downloaded from here, and the installation is just the next next finished installation.

I open my PowerShell terminal and log into Azure using the “Az login” command.

A website opens when I sign into mu account using my credentials.

When I have signed in, I get a list of the subscriptions my account has access to.

I need to select my account, and I do that with the command “az account set –subscription IdOfSubscription” The ID is shown in the first screenshot.

Now that Terraform is ready on my local machine, I can create the configurations I need in Terraform. I will create a resource group and storage account in Azure. I create a resource group called “Terraform-state” and a storage account named “cloudninjaterraformstate”. When done, it will look like this.

In my storage account I create a container name “tfstate”

I am using Terraform version 0.14.7 in this guide, and the documentation from Terraform states that it is recommended to use required_providers declaration after version 0.13.

I open Visual Studio Code (VS code) and create my first configuration file named “backend.tf”. I found the required_providers information here. I paste that code into my new file.

Now I can run the command “terraform init” to initialize terraform in this folder.

I can see that the backend file is working without errors, so now I can run “Terraform plan -out=’backend.plan'” to save my current configuration. Notice that a new file is created with contains the plan for deployment.

To verify that terraform is using the states’ storage account, I browse to the container and verify a new file is generated here.

Now I am ready to begin the configuration files for the actual infrastructure I want to deploy in Azure. The next part of this series will contain the creation of the resource groups I plan to have in the environment.

Share this Post

1 Comment

  1. First to read it all šŸ˜‰

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*