How to estimate Azure costs from Terraform
Estimate Azure costs from Terraform configurations including Reserved Instances, Azure Hybrid Benefit, Spot VMs, and Premium SSD tier mapping. Completes the cloud trilogy alongside AWS and GCP.
Quick answer
Install C3X (brew install c3xdev/tap/c3x), point it at your Terraform directory (c3x estimate --path .), and you get a line-item Azure cost breakdown in seconds. Reserved Instances and Azure Hybrid Benefit apply via c3x-usage.yml. Spot VMs are detected from the resource configuration. No Azure credentials required.
Azure cost estimation from Terraform follows the same workflow as AWS and GCP but has a few Azure-specific patterns worth knowing. Reserved Instances work differently than AWS RIs. Premium SSD disks use tier-based pricing instead of pure per-GB. App Service plans bill differently from VMs. This post walks through the workflow end-to-end with Azure-specific examples.
Step 1: Install and verify
brew install c3xdev/tap/c3x
c3x --versionStep 2: Estimate an Azure project
Point c3x at your Terraform directory:
c3x estimate --path /path/to/terraformSample output for a small Azure stack:
Name Monthly Qty Unit Monthly Cost
azurerm_linux_virtual_machine.api
├─ Compute (Standard_D2s_v5, Linux, pay-as-you-go) 730 hours $70.08
└─ OS disk (Premium SSD P10) $19.71
azurerm_postgresql_flexible_server.main
├─ Compute (GP_Standard_D2s_v3, Zone-redundant HA) 730 hours $394.20
└─ Storage (general-purpose SSD) 200 GB $23.00
azurerm_storage_account.assets
├─ Blob storage (Hot, LRS) 500 GB $9.50
└─ Read operations (estimated) $0.10
OVERALL TOTAL $516.59Notice three Azure-specific things in the output: the disk shows as P10 (Premium SSD tier 10), not "128 GB at $0.10/GB"; the Postgres compute charge reflects the Zone-Redundant HA premium (roughly 2x base price); the storage account shows blob storage in the Hot tier with LRS replication.
For per-resource pricing details, see the catalog pages for azurerm_linux_virtual_machine, azurerm_postgresql_flexible_server, and azurerm_storage_account.
Step 3: Azure-specific patterns
Reserved Instances
Azure Reserved Instances work at the subscription level. You commit to a VM size (Standard_D2s_v5, for example) for 1 or 3 years and Azure applies the discount to any matching VM in the scope. Configure in c3x-usage.yml:
# c3x-usage.yml
resource_usage:
azurerm_linux_virtual_machine.api:
purchaseOption: "reserved"
purchaseOptionTerm: "1yr"c3x applies the Reserved Instance rate from the Retail Prices API. Typical discount is 30-50% for 1-year commitments, up to 65% for 3-year all-upfront.
Azure Hybrid Benefit
If you have eligible Windows Server or SQL Server licenses with Software Assurance, you can bring your own license to Azure and save on the per-hour licensing premium. Add to the resource:
resource "azurerm_windows_virtual_machine" "app" {
name = "app-vm"
license_type = "Windows_Server" # AHB enabled
size = "Standard_D2s_v5"
# ...
}c3x detects license_type and applies the base Linux rate (minus the Windows premium). The savings are substantial: a Windows VM typically costs 40-50% more than the Linux equivalent. AHB closes most of that gap.
Spot VMs
For fault-tolerant workloads, Spot VMs cost 60-90% less:
resource "azurerm_linux_virtual_machine" "batch_worker" {
name = "batch-worker"
size = "Standard_D2s_v5"
priority = "Spot"
eviction_policy = "Deallocate"
max_bid_price = -1 # use current Spot price
# ...
}c3x reads priority and applies the Spot pricing tier. Same principles as AWS Spot — see our Spot instances post for the design patterns.
Premium SSD tier mapping
Azure Premium SSDs are billed per tier (P1 through P80), not per GB. Each tier has fixed IOPS, throughput, and a fixed monthly price. c3x reads the disk size and maps it to the smallest tier that fits.
Important pricing quirk: a 130 GB disk maps to P15 (256 GB tier) because it crosses the 128 GB threshold. You pay the P15 price even if you use less storage. Right-sizing means staying just under a tier boundary, not just provisioning what you need.
See the azurerm_managed_disk catalog page for tier-by-tier pricing.
Step 4: Diff branches
c3x diff --path . --compare-to mainSample output for a PR that resizes a VM and adds a new managed disk:
~ azurerm_linux_virtual_machine.api
└─ Compute (Standard_D2s_v5 -> Standard_D4s_v5) +$70.08 ($70.08 -> $140.16)
+ azurerm_managed_disk.data
└─ Premium SSD P20 (512 GB tier) +$73.73/month
Monthly cost change: +$143.81 ($516.59 -> $660.40)Step 5: CI integration
The setup-c3x GitHub Action works for Azure Terraform identically to AWS:
# .github/workflows/cost.yml
on: pull_request
jobs:
cost:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: c3xdev/setup-c3x@v1
with:
path: .For full CI integration including Azure DevOps Pipelines, see the CI/CD documentation. For budget gating, see budget guardrails in CI.
Azure-specific cost dimensions to watch
Application Insights ingestion
Bills via Log Analytics at $2.30/GiB. For high-traffic apps with 100% telemetry capture, this can be massive. Set sampling_percentage on the resource (10-20% is usually sufficient). See the azurerm_application_insights catalog page.
Log Analytics for AKS
Container Insights on AKS sends logs to Log Analytics. A standard AKS cluster generates 5-20 GiB/day. At $2.30/GiB ingest, that's $345-1,380/month per cluster. See the azurerm_log_analytics_workspace catalog page for mitigations.
Bandwidth and ExpressRoute
Azure outbound bandwidth costs $0.087/GB after the first 100 GB free per month. ExpressRoute Direct ports add fixed per-hour fees. Cross-region traffic within Azure also has separate rates.
Premium tier Cosmos DB and Service Bus
Cosmos DB Premium and Service Bus Premium have significantly higher per-RU and per-hour rates than Standard. Make sure the features (e.g., VNet integration, longer message retention) actually justify the cost.
A real Azure cost comparison
Typical small production stack:
- 2× azurerm_linux_virtual_machine (Standard_D2s_v5): $140/month
- 1× azurerm_postgresql_flexible_server (D2s_v3 HA): $394/month
- 1× azurerm_storage_account (500 GB Hot LRS): $10/month
- 1× azurerm_application_insights (sampling at 10%): $50/month
- 1× azurerm_redis_cache (C1 Standard): $43/month
- Total: ~$637/month
With 1-year Reserved Instances on compute and 1-year Reserved Capacity on Cosmos: ~$420/month (34% savings).
FAQ
Does C3X support Azure Terraform configurations?
Yes. C3X parses azurerm_* resources alongside AWS and GCP resources in the same Terraform configuration. Pricing data comes from the Azure Retail Prices API, refreshed daily. No Azure credentials are required for estimation.
How does C3X handle Azure Reserved Instances?
Set purchaseOption: 'reserved' on the resource in c3x-usage.yml and specify the term (1yr or 3yr). C3X applies the Reserved Instance discount rate from the Retail Prices API. Reservations apply at the subscription level in Azure but c3x estimates them per-resource as a reasonable proxy.
What about Azure Spot VMs?
Add priority = 'Spot' to the VM resource (and the eviction_policy attribute). C3X detects the Spot configuration and applies Spot pricing, which is typically 60-90% off pay-as-you-go rates.
Does C3X handle Azure Hybrid Benefit?
Yes for Windows VMs and SQL Server. Set license_type = 'Windows_Server' on the VM resource or license_type = 'AHUB' on SQL resources. C3X applies the Azure Hybrid Benefit discount, which can cut Windows licensing costs by 40% or more.
How is Azure estimation different from AWS or GCP?
Three notable differences. Azure has SKU-based pricing for storage and managed disks (P10, P15, etc.) rather than purely per-GB; C3X maps disk sizes to tiers automatically. Azure App Service plans use a different model than EC2; pricing follows the plan tier (B1, S1, P1v3, etc.). And Azure has Reserved Instances that work differently from AWS Reserved Instances; you reserve compute capacity at a SKU level, not per-VM.
What Azure services does C3X cover?
All major services: VMs, AKS, App Service, Functions, Storage, Cosmos DB, Postgres/SQL flexible servers, Redis Cache, Container Registry, Application Gateway, Key Vault, Log Analytics, Application Insights, Event Hubs, and more. See the resource catalog for the complete list.
Where to go from here
- Full resource catalog with Azure-specific pricing dimensions for every supported resource
- For the AWS equivalent workflow: how to estimate AWS costs from Terraform
- For GCP: how to estimate GCP costs from Terraform
- For PR-level cost gating: budget guardrails in CI
Share this post
Try C3X on your own Terraform
Free and open source. No API key required. One command to install, one command to estimate.