Well-Architected Framework
Create cloud budgets
Cloud spending can quickly get out of control without proper oversight and management. According to the 2023 HashiCorp State of Cloud Strategy Survey, 94% of respondents experienced avoidable cloud costs. Proactive budget creation, automated alerts, and anomaly detection give you the visibility and control to maintain predictable spending and prevent cost overruns.
Why create cloud budgets
Automating cloud budgets and spending alerts addresses the following operational challenges:
Prevent cost overruns: Without budget thresholds and alerts, cloud spending can grow unchecked between billing cycles. By the time you review a monthly statement, overruns may already be significant and difficult to attribute to specific teams or projects.
Track spending by team and project: Cloud environments shared across multiple teams make it difficult to understand what is driving costs. Budget scoping by service, account, or tag gives you granular visibility into where money goes so you can allocate costs accurately and hold teams accountable.
Detect unusual spending patterns automatically: Legitimate usage changes can look identical to misconfigurations or unauthorized access. Automated alerts based on forecasted spend help you respond early, before anomalies compound into significant overruns.
Improve financial planning and forecasting: Historical budget data provides the baseline you need to make informed capacity plans. Teams can use spending trends to project future costs, justify infrastructure investments, and find opportunities to cut waste.
Create spending limits and notifications
Most major cloud providers offer native tools to set budget thresholds, monitor spending, and receive alerts when spending approaches or exceeds defined limits.
Terraform lets you define and manage cloud budgets across your organization using reusable modules. Each module can apply budget thresholds, alerts, and spending limits to resources for different teams, projects, or environments.
If you track resources by tags, define a clear tagging strategy to ensure budgets apply correctly. Terraform enforces tagging policies and tags all resources consistently. Creating infrastructure manually can lead to incorrect or missing tags on resources and result in inaccurate budget tracking.
Cloud budget configuration with Terraform
The following Terraform configuration creates an AWS EC2 budget. This budget tracks EC2 instance costs and sends an alert to cloud-costs@example.com when the forecasted cost exceeds 100% of the budget. You can set similar budgets and alerts for other cloud providers, such as Azure and GCP.
resource "aws_budgets_budget" "ec2" {
name = "budget-ec2-monthly"
budget_type = "COST"
limit_amount = "1200"
limit_unit = "USD"
time_period_end = "2087-06-15_00:00"
time_period_start = "2017-07-01_00:00"
time_unit = "MONTHLY"
cost_filter {
name = "Service"
values = [
"Amazon Elastic Compute Cloud - Compute",
]
}
notification {
comparison_operator = "GREATER_THAN"
threshold = 100
threshold_type = "PERCENTAGE"
notification_type = "FORECASTED"
subscriber_email_addresses = ["cloud-costs@example.com"]
}
tags = {
Environment = "production"
Team = "engineering"
ManagedBy = "terraform"
}
}
The configuration includes the following key components:
- limit_amount: Defines the monthly spend limit.
- notification: Defines the notification criteria, including the recipient email.
- tags: Applies tags to the budget resource, not the EC2 instance. Tags allow you to filter and organize budgets in the billing console.
For AWS environments, you can use the aws_budgets_budget resource to create budgets that track spending by service, linked account, tag, or other dimensions. You can specify the budget amount, time period, and notification thresholds.
For Azure environments, the azurerm_consumption_budget_subscription resource lets you create subscription-level budgets with similar notification capabilities. You can define multiple notification rules that trigger at different spending thresholds.
For Google Cloud Platform, the google_billing_budget resource operates at the billing account level, and you can filter by project, service, or label. GCP budgets support both actual and forecasted spending alerts.
HashiCorp resources
- Learn how to tag cloud resources to accurately scope and filter budgets by team, environment, or project.
- Learn how to detect cloud spending anomalies to catch cost spikes that fall within budget thresholds.
- Use HCP Terraform cost estimation to preview the cost impact of infrastructure changes before applying them.
- Start learning Terraform with the Get started tutorials.
- Read the aws_budgets_budget resource documentation for AWS budget configuration options.
- Read the azurerm_consumption_budget_subscription resource documentation for Azure budget configuration options.
- Read the google_billing_budget resource documentation for GCP budget configuration options.
External resources
- AWS Budgets: Getting started with AWS Budgets
- Azure Cost Management and Billing: Create and manage budgets
- Google Cloud Budgets and alerts: Creating budgets
Next steps
In this section of Manage cost, you learned how to create cloud budgets and configure spending alerts to prevent cost overruns using Terraform. Manage cost is part of the Optimize systems pillar.
To learn more about managing resources with Terraform, see the following resources: