Terraform Azure VM Config Builder

Generate Terraform HCL for an Azure Virtual Machine with networking

Build Terraform HCL for an Azure Linux VM with the full networking stack — resource group, virtual network, subnet, network interface, OS disk, and SSH or password admin authentication.

What resources does an Azure VM require in Terraform?

A working Linux VM needs a resource group, a virtual network, a subnet, a network interface, and the azurerm_linux_virtual_machine itself referencing the NIC and an OS disk. This builder emits all of them wired together with the correct references.

Stand up an Azure VM with Terraform, batteries included

An Azure virtual machine is never just one resource — it needs a network to live in. This builder generates the complete dependency chain (resource group, virtual network, subnet, NIC) plus the azurerm_linux_virtual_machine itself, with the cross-references already wired so terraform apply works first time.

How it works

Terraform creates Azure resources in dependency order using interpolated references. The VM references its network interface ID, the NIC references the subnet, the subnet references the virtual network, and everything references the resource group’s name and location. By chaining azurerm_resource_group.<id>.name style references, Terraform builds the correct graph and provisions resources in the right sequence.

For authentication, the recommended SSH path injects an admin_ssh_key block that reads your public key with file("~/.ssh/id_rsa.pub"). The password path sets disable_password_authentication = false and pulls the secret from a sensitive Terraform variable, so the credential never appears in your committed HCL.

Tips and notes

  • Prefer SSH keys — they avoid password brute-forcing and don’t leak into state as readable strings.
  • The OS image is pinned to Ubuntu 22.04 LTS gen2; change the source_image_reference block if you need a different distro.
  • Choose Premium_LRS for production disks and Standard_LRS to minimise cost on dev VMs.
  • Add a network security group and public IP if the VM needs inbound access — this template keeps it internal-only by default.