DEV Community

Ozan Guner
Ozan Guner

Posted on

Terraform Basics – Week 1: Deploying Your First Azure VM

Table of Contents

1. Intro

2. Prerequisites

3. What We’re Building This Week

4. Creating Our Folder and File Structure

5. Why Multiple .tf Files

6. Step by Step Implementation

a) providers.tf

b) resource-group.tf

c) virtual-network.tf

d) virtual-machine.tf

7. Deploying to Azure

8. What We’ll Improve Next Week

9. Wrap-Up

1. Intro

Welcome to Week 1 of my new Terraform Basics series.
Each week I will build on what we did before, starting simple and gradually layering in real-world examples and best practices as we go along.

When you’re used to clicking through Azure Portal, the idea of spinning up infrastructure through code can feel strange. But once you see how clean, repeatable, and scalable it is, there’s no going back. Terraform makes that transition smooth: you describe your setup in plain text, and Terraform builds it exactly the same way every single time.

2. Prerequisites

If you’d like to follow along, here’s what you’ll need:

Install Terraform, VS Code and the VS Code Terraform Extension on your machine. Here's a quick video that demonstrates how to do all 3.

Give Terraform the necessary access to your Azure Tenant, by following the video here.

Once that’s done, you’re ready to go.

3. What We’re Building This Week

Architecture Diagram

We’re starting small: a single Windows virtual machine in Azure, with the basic building blocks it needs to exist: A resource group, virtual network, subnet, and a network interface.

GitHub repository
to access all terraform files.

4. Creating Our Folder and File Structure

To get started, we’ll create our Terraform project folder and organize it like this:

Folder Structure

5. Why Multiple .tf Files

You can put everything in a single main.tf file, but organizing your configuration by purpose keeps things cleaner as you expand.

providers.tf - Defines the Azure provider
resource-group.tf - Creates a resource group
virtual-network.tf - Creates the virtual network and subnet
virtual-machine.tf - Creates the NIC and VM

Think of it like keeping different tools in different drawers. Everything still works together, but finding and modifying parts later becomes much easier.
6. Step by Step Implementation

Let’s go through each file.

a) providers.tf
This tells Terraform which cloud you’re using, in our case Azure.

providers.tf

b) resource-group.tf
A resource group is a logical container for your Azure resources.

resource-group.tf

c) virtual-network.tf

The virtual network defines a private address space, and the subnet carves out a smaller range inside it for your VM and any other future resources you may choose to put there.

virtual-network.tf

d) virtual-machine.tf

This file defines both the network interface and the VM itself. The NIC connects the VM to the subnet, and the VM block creates the Windows Server 2025 instance.

virtual-machine.tf

7. Deploying to Azure

For Windows, open a command prompt or a PowerShell and navigate to your Terraform project folder you created (in my case, Azure). From your project folder, run the following commands :

  1. terraform init - Initializes terraform, installs the required providers

terraform-init

  1. terraform plan - Shows you what resources are going to be added, deleted, or changed.

terraform-plan

  1. terraform apply - Terraform provisions each resource exactly as defined.

terraform-apply

8. What We’ll Improve Next Week

Right now everything is hard-coded. It works, but it’s not flexible or scalable.

In Week 2 we’ll introduce variables for names, sizes, and credentials, add outputs to display information like IP addresses, apply tags for organization and cost tracking, and more!

9. Wrap-Up

In under a hundred lines of Terraform, we built a complete Azure VM from scratch. No clicking through the portal, no guessing, and fully repeatable every time. When you are deploying resources constantly, using Infrastructure as Code to deploy resources becomes very efficient.

This is where Infrastructure as Code really shows its value: consistency, transparency, and control.

I hope this was helpful to understand Terraform Basics, and hope to see you again in Week 2!

Top comments (0)