Azure VM Example with Terraform

Walk through a single-file Azure VM deployment that provisions networking, security rules, and an Nginx-ready Linux machine.

TrackTerraform Learning Journey
Current SectionCloud Provisioning
Progress8 of 12

Azure VM Example with Terraform

This folder contains a compact Azure example that provisions the full chain needed for a basic virtual machine: a resource group, virtual network, subnet, public IP, network security group, NIC, and Linux VM.

What this example teaches

  • How the azurerm provider models Azure infrastructure in Terraform.
  • How network resources depend on each other before a VM can be created.
  • How to expose SSH and HTTP with an NSG.
  • How to bootstrap a VM using custom_data.

Files to inspect

  • main.tf: the end-to-end Azure deployment in one file.

Suggested workflow

  1. Read the resource dependency chain from top to bottom.
  2. Run terraform init to install the Azure provider.
  3. Run terraform plan and confirm the resource graph makes sense before applying.
  4. Replace hardcoded secrets and credentials before using this in a real environment.

Notes before reuse

  • The sample uses a plaintext admin password, which is fine for learning but not for production.
  • In a real project, move repeated values into variables and store state remotely.
  • Split networking and compute into modules once the single-file layout is clear.