azurerm_linux_virtual_machine cost estimation
A single Linux VM. Billed per hour for the chosen size plus a separate managed OS disk. A Standard_D2s_v5 runs ~$70/month before the disk.
An azurerm_linux_virtual_machine is the modern, single-VM resource (it replaced the older azurerm_virtual_machine). Cost has two parts that engineers routinely forget are separate line items: the compute (the VM size, billed per second but quoted per hour) and the managed OS disk, which bills whether the VM is running or stopped-deallocated.
The compute rate is set entirely by the size. A Standard_D2s_v5 (2 vCPU, 8 GiB) is about $0.096/hour, so ~$70/month if it runs 24/7. Memory-optimized (E-series) and compute-optimized (F-series) sizes cost more per vCPU. The rate quoted on the Azure pricing page is pay-as-you-go Linux; Windows images add a per-core licensing surcharge that Linux avoids, which is the main reason Linux VMs are cheaper for identical hardware.
The OS disk is a managed disk billed by tier, not by used bytes. A 128 GB Premium SSD (P10) is a flat ~$19.71/month even if you only write 5 GB to it, because Azure provisions the whole tier. Standard SSD (E-tier) and Standard HDD (S-tier) are cheaper but slower. Picking StandardSSD_LRS over Premium_LRS for a dev box roughly halves the disk cost.
The biggest real-world lever is that compute stops billing when the VM is deallocated (not just powered off from inside the guest), but the disk keeps billing. A fleet of dev VMs auto-deallocated nights and weekends pays compute for ~40% of the hours, while the disks bill the full month.
c3x estimates the compute from the size attribute and the OS disk from os_disk_storage_account_type and os_disk_disk_size_gb. A reserved instance or savings plan is modelled separately.
Terraform example
A minimal but realistic configuration that C3X can estimate.
resource "azurerm_linux_virtual_machine" "app" {
name = "app-vm"
resource_group_name = azurerm_resource_group.main.name
location = "eastus"
size = "Standard_D2s_v5"
admin_username = "azureuser"
network_interface_ids = [azurerm_network_interface.app.id]
admin_ssh_key {
username = "azureuser"
public_key = file("~/.ssh/id_rsa.pub")
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
disk_size_gb = 128
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts-gen2"
version = "latest"
}
}Pricing dimensions
What you actually pay for when you provision azurerm_linux_virtual_machine.
| Dimension | Unit | What's being charged |
|---|---|---|
| Compute (VM size) | per hour | Set by the size attribute. Billed per second while the VM is running; stops when the VM is deallocated. $0.096/hour ≈ $70.08/month for Standard_D2s_v5 (Linux, eastus) |
| OS managed disk | per disk-month | Flat per-tier charge sized to the disk, not bytes used. Bills whether the VM runs or not. $19.71/month for a 128 GB Premium SSD (P10) |
| Data disks (if attached) | per disk-month | Each azurerm_managed_disk attached to the VM bills on its own tier. Estimated as separate resources. |
Sample C3X output
A Standard_D2s_v5 with a 128 GB Premium SSD OS disk, running 24/7:
azurerm_linux_virtual_machine.app
├─ Virtual machine (Standard_D2s_v5) 730 hours $70.08
└─ OS disk (Premium SSD P10) 1 disk $19.71
Monthly $89.79Optimization tips
Common ways to reduce azurerm_linux_virtual_machine cost without changing the workload.
Auto-deallocate non-production VMs off-hours
~60% of compute on non-prodCompute stops billing when a VM is deallocated. An Azure Automation or DevTest Labs schedule that deallocates dev/test VMs nights and weekends cuts compute to ~40% of a 24/7 month. The OS disk still bills, so the saving is on compute only.
Buy a reserved instance or savings plan for steady VMs
40–60% on steady computeA 1-year reservation on a VM that genuinely runs 24/7 is ~40% cheaper than pay-as-you-go; 3-year is ~60%. Only commit for baseline capacity you're certain you'll keep running.
Right-size the OS disk tier
~50% on the OS diskA dev box rarely needs Premium SSD. Switching the OS disk from Premium_LRS (P10, ~$19.71) to StandardSSD_LRS (E10, ~$9.60) halves disk cost with no impact on a workload that isn't disk-bound.
Use Spot VMs for interruptible workloads
Up to 90% for interruptible workSpot pricing on a D2s_v5 is often 70–90% below pay-as-you-go. Right for batch jobs, CI runners, and anything that tolerates eviction. Not for stateful services without checkpointing.
FAQ
Does a stopped Azure VM still cost money?
It depends on how it's stopped. 'Stopped' from inside the guest OS (or 'Stopped' state) keeps billing compute because the capacity is still reserved. Only 'Stopped (deallocated)' releases the compute and stops the hourly charge. The OS and data disks bill in both cases.
Why is the same VM size cheaper on Linux than Windows?
Windows VMs include a per-core Windows Server license in the hourly rate; Linux doesn't. For identical hardware the Linux rate is the bare compute. Azure Hybrid Benefit lets you bring your own Windows license to close the gap.
How does c3x price the OS disk?
From os_disk_storage_account_type (Premium_LRS / StandardSSD_LRS / Standard_LRS) and os_disk_disk_size_gb, mapped to Azure's tier ladder (P/E/S 4–50). Managed disks bill per provisioned tier, so a 100 GB and a 128 GB disk both land on the same tier.
Should I use azurerm_linux_virtual_machine or azurerm_virtual_machine?
Use azurerm_linux_virtual_machine for new work. The older azurerm_virtual_machine is deprecated by the provider. c3x prices both, but the modern resource maps cleanly to a single VM and a single OS disk.
Related resources
Estimate this resource in your own Terraform
Free, open source, no API key. C3X parses your Terraform and shows line-item cost for every resource, including azurerm_linux_virtual_machine.