Wednesday, 4 February 2026

Create a Linux Virtual Machine in Azure Using Terraform

Create a Linux Virtual Machine in Azure Using Terraform
vmcreation



Introduction

Infrastructure as Code (IaC) helps automate cloud resource provisioning in a reliable and repeatable way. Terraform is one of the most widely used IaC tools for managing cloud infrastructure.

In this blog, you will learn how to create a Linux Virtual Machine in Microsoft Azure using Terraform, configure a remote backend for state management, and connect to the VM using SSH.

By the end of this guide, you will be able to:

1. Configure Azure provider in Terraform

2. Store Terraform state in Azure Storage Account

3. Create networking resources (VNet, Subnet, NSG, Public IP)

4. Deploy a Linux Virtual Machine

5. Connect securely to the machine


Prerequisite:

Before starting, ensure that you have:

  1. An active Azure subscription

  2. Terraform installed on your machine

  3. An existing Azure Storage Account for Terraform state

  4. An SSH key pair on your local system

To generate an SSH key (if not already available):

ssh-keygen -t rsa -b 4096

Project Structure

Create a new project directory and organize files as follows:

Author Details

Hi, I'm Prashant — a full-time software engineer with a passion for automation, DevOps, and sharing what I learn. I started Py-Bucket to document my journey through tools like Docker, Kubernetes, Azure DevOps, and PowerShell scripting — and to help others navigate the same path. When I’m not coding or writing, I’m experimenting with side projects, exploring productivity hacks, or learning how to build passive income streams online. This blog is my sandbox — and you're welcome to explore it with me. Get in touch or follow me for future updates!

About Me

About the Author

Author

Hi, I'm Prashant — a full-time software engineer with a passion for automation, DevOps, and sharing what I learn. I started Py-Bucket to document my journey through tools like Docker, Kubernetes, Azure DevOps, and PowerShell scripting — and to help others navigate the same path.

When I’m not coding or writing, I’m experimenting with side projects, exploring productivity hacks, or learning how to build passive income streams online. This blog is my sandbox — and you're welcome to explore it with me.

Get in touch or follow me for future updates!