Getting started with Terraform

In this guide, I show the path from install to deployment: I install Terraform, I prepare my Azure login using Azure CLI, and then I run a “single server” Terraform setup so you can see the process end-to-end.

Terraform described

Terraform is a framework built by Hashicorp that lets you manage cloud infrastructure for Azure and Amazon Web Services using text files only. This does it by talking with the Azure Resource Manager API, the underlying system that manages Azure Environments, Azure CLI and Azure PowerShell.

Terraform code is declarative code, which means you describe the desired end result instead of writing every step the system needs to take, like you would often do in a PowerShell script. In this case, we tell ARM to create a Virtual Machine with the name, IP address, and other settings we specify. It is a bit like telling a chef which dish you want and which ingredients to use, and then letting the chef prepare it for you.

In simple words:

  1. You write what you want (for example: “make a server, with a IP linked and a NSG”).
  2. Terraform creates a “plan” to show what it will do before touching your cloud environment
  3. Then Terraform applies the plan using Azure CLI to build (or change) the Azure resources according to your plan

jv-media-8507-99d18c372f66.png

The topology of the resources we will deploy in this guide is:

Resource typeResource name
Resource grouprg-jv-
OS diskosdisk-jv-
VNETvnet-jv-
NICnic-jv-
Public IPpip-jv-
NSGnsg-jv-
VMvm-jv-

After the resources are deployed, a PowerShell script is executed in the VM to install the Active Directory role and to configure it.

In this guide, I will show how to install Terraform, prepare your Azure login, start using Terraform and run a single server Terraform setup I have made with the needed dependencies and security.


Requirements

  • Around 30 minutes of your time
  • Moderate knowledge of Azure and PowerShell
  • Basic knowledge of Terraform and Infrastructure as Code
  • Visual Studio Code
  • Terraform
  • Azure CLI

Step 1: Installation of Terraform

In this step, I will install Terraform on my local computer. First, go to the official Terraform installation page.

https://developer.hashicorp.com/terraform/install

Image

On this Terraform installation page, download the Windows version of Terraform.

After downloading the ZIP file, extract the file. Inside the ZIP file you will find the terraform.exe file. For this guide, I place the Terraform binary in the folder below. Create the folder below if it does not already exist.

  • C:\Tools\Terraform

Then place terraform.exe inside this folder.

Image

Now Terraform is installed on the computer, but Windows still needs to know where it can find terraform.exe.

To make this work from every PowerShell window, I add the Terraform folder to the Windows user Path. If you have a other location, change the location.

PowerShell
$terraformlocation = "C:\Tools\Terraform"
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")

if ($userPath -notlike "*$terraformlocation*") {
    [Environment]::SetEnvironmentVariable("Path", "$userPath;$terraformlocation", "User")
}

This action sets the variable in the Windows known variables. This is similar to this GUI option.

After changing the Path, close all open PowerShell and Visual Studio Code windows. Then open a new PowerShell window and check if Terraform is working:

PowerShell
terraform -version

If Terraform is installed correctly, the Terraform version will be shown in the terminal.

PowerShell
PS C:\Users\InfoJustinVerstijnen> terraform -version
Terraform v1.15.2
on windows_amd64

Terraform is now installed and ready to use.


Step 2: Installation of Azure CLI

We can now install the Azure CLI shell if not already installed, as Terraform needs a way to authenticate to Microsoft Azure. The most easy way to install Azure CLI is through with winget.

Open PowerShell as Administrator and run the command below:

PowerShell
winget install --exact --id Microsoft.AzureCLI

The installation can take some time, so please have a little patience. This process can take up to 15 minutes.

After the installation is completed, close all open PowerShell and Visual Studio Code windows. This is needed so Windows can reload the new environment variables and initializing the commands needed.

Then open a new PowerShell window and check if Azure CLI is working:

PowerShell
az version

If Azure CLI is installed correctly, the Azure CLI version information will be shown in the terminal.

PowerShell
PS C:\Users\InfoJustinVerstijnen> az version
{
  "azure-cli": "2.86.0",
  "azure-cli-core": "2.86.0",
  "azure-cli-telemetry": "1.1.0",
  "extensions": {
    "account": "0.2.5",
    "logic": "1.1.0"
  }
}

Azure CLI is now also installed and ready to use.


Step 3: Downloading my Single Server Terraform setup

For the ease of this guide, I have a full template available that deploys the resources as stated in the description at the top of the page. We only need to change some variables to your likings.

Go to my GitHub repository to download the simple 1 server setup:

Download Terraform setup from GitHub

Click on “Code” and click Download ZIP and place it on your computer on a known place. This folder contains the Terraform setup, with some preconfigured files. For this guide we only need to change information in the terraform.tfvars file.

In the ZIP file we can find 9 files which all have their own purpose:

File nameContains
scripts/bootstrap-dc.ps1The after deployment PowerShell script
LICENSEThe license of the GitHub Repo
README.mdThe instructions of the repo, superseded if you follow this guide
locals.tfThe naming scheme of the deployment
main.tfThe resources which all will be deployed using the set variables. We can see this as the full recipe
outputs.tfThe outputs like names of resources
terraform.tfvarsThe project specific variables which we can configure to our likings
variables.tfAll possible renameable fields
versions.tfAll versions of dependencies

Now we are ready to change the project to your likings.


Step 4: Changing the project variables

In the file terraform.tfvars, you can change the project variables. This file is where you set values like names, IP addresses, and other settings for your deployment. Review everything before saving.

Image

Change the information to your likings. The things you are required to change are:

  • Line 4: Subscription ID
  • Line 5: Project name
  • Line 13: Your IP address for whitelisting purposes
  • Line 16, 17, 18, 19, 20: Your Active Directory details

After changing this information, save the file and we are now ready to go.


Step 5: Deploying the Terraform project

Now we are finally ready to deploy our Terraform project to Azure. We will login to Azure CLI and then prepare Terraform for the deployment. In my Azure Environment, nothing is available using the projects’ names:

Image

Let’s sign in to Azure CLI using this command:

PowerShell
az login

Then login to your Azure account where the deployment must be done. Also be sure to perform the additional verification steps.

Image

After that, Azure CLI can ask for additional information like the subscription you want to deploy the resources into. If you no have already done so, copy the Subscription ID and paste this into line 4 of the terraform.tfvars file.

Now navigate to the folder of your Terraform project in Visual Studio Code terminal.

Image

Then we can perform these commands:

PowerShell
terraform init

Image

Now Terraform is initialized, creating some temporary files. Then validate the configuration:

PowerShell
terraform validate

Image

After validation with zero errors, create a plan. This command (Terraform plan) creates a file that shows what will be added to the Azure Environment.

PowerShell
terraform plan -out main.tfplan

Image

Finally, apply the plan:

PowerShell
terraform apply main.tfplan

Terraform will now start the full deployment based on your Terraform variables and plan.

Image

Now the complete deployment will be executed and built in Azure. In the Terminal Window you can review the status. The complete deployment will take around 5 minutes.

After some seconds, still in deployment, we can already see the resource group being created:

After around 5 minutes, Terraform will inform us that the deployment is finished, giving us information about what has been done, like the IP address to connect with RDP.

If you need to remove all the resources Terraform created, you can run:

PowerShell
terraform destroy -auto-approve

This willautomatically destroy every resource created by the Terraform plan, skipping the extra approval step.


Step 6: The results

After terraform apply finishes, Terraform has built the resources defined in the Terraform setup. In my case, this took around 5-6 minutes and after that, the virtual machine will be restarted to apply the Active Directory installation. Let’s check the results:

  • check the output shown by Terraform in your terminal, and
  • check the Azure resources in the Azure Portal for the resource group that was created/used by this Terraform setup

This is the newly created resource group for example. All dependent resources are created.

And in the VNET, the DNS server is also changed to get new servers into the DNS/Active Directory of the created servers.

And in the VM, everything is configured according to plan:

Image

Pretty cool and much faster and more according to plan than deploying everything by hand.


Step 7: Changes to Terraform project (optional)

If you change something in the Terraform setup (for example in terraform.tfvars), you can update Azure again by running these commands:

PowerShell
terraform plan -out main.tfplan
terraform apply main.tfplan

Terraform will compare what it wants (new plan) with what already exists, and then apply the changes.

If you want to remove everything completely, use the terraform destroy command first.

PowerShell
terraform destroy -auto-approve

Knowledge check

Knowledge check
This quiz needs JavaScript to show the questions and feedback.

Summary

Terraform helps you deploy Azure resources in a repeatable way using Infrastructure as Code. With the steps above, you installed Terraform and Azure CLI, prepared your settings in terraform.tfvars, then used terraform init, terraform validate, terraform plan, and terraform apply to deploy your single server setup. This structured format follows the same blog layout pattern from my post template.

The advantages of Terraform are fast deployment, modular setup in code, and easy scalable deployment.

Thank you for reading this post and I hope it was helpful!

Sources

These sources helped me by writing and research for this post;

  1. https://developer.hashicorp.com/terraform/install

 

End of the page 🎉

You have reached the end of the page. You can navigate through other blog posts as well, share this post on X, LinkedIn and Reddit or return to the blog posts collection page. Thank you for visiting this post.

If you think something is wrong with this post or you want to know more, you can send me a message to one of my social profiles at: https://justinverstijnen.nl/about/

Go back to Blog homepage

If you find this page and blog very useful and you want to leave a donation, you can use the button below to buy me a beer. Hosting and maintaining a website takes a lot of time and money. Thank you in advance and cheers :)

Buy me a beer

The terms and conditions apply to this post.

Last modified July 6, 2026: Scheduled posts (250b667)