Skip to main content

How to set up budgets and cost alerts on Google Cloud

Create Google Cloud billing budgets with threshold and forecast alerts, project scoping, and Pub/Sub automation to control and react to spend.

Difficulty
Beginner
Duration
30 minutes
Steps
6

Google Cloud budgets track spend against a limit and notify you when actual or forecasted cost crosses thresholds. Unlike a hard cap, a budget is a guardrail, but you can wire it to Pub/Sub to automate responses such as disabling billing on a runaway project.

Prerequisites

  • A Google Cloud billing account and the gcloud CLI.
  • Terraform.

Steps

1. Identify the billing account

gcloud billing accounts list

Budgets attach to a billing account, not a project.

2. Create a budget

resource "google_billing_budget" "monthly" {
  billing_account = var.billing_account
  display_name    = "monthly"
  amount { specified_amount { currency_code = "USD"; units = 500 } }
}

3. Add threshold rules

Alert at multiple percentages, including a forecast-based one:

threshold_rules { threshold_percent = 0.8 }
threshold_rules { threshold_percent = 1.0; spend_basis = "FORECASTED_SPEND" }

4. Scope to projects

Use budget_filter to track specific projects, services, or labels rather than the whole account.

5. Publish to Pub/Sub

Attach a Pub/Sub topic to the budget so each threshold breach publishes a message your automation can consume:

all_updates_rule { pubsub_topic = google_pubsub_topic.budget.id }

6. Automate a response

Subscribe a Cloud Function to the topic. For a non-production project, it can call the Billing API to disable billing when spend hits 100%, the only true hard stop on GCP.

Verification

In the Billing console, confirm the budget shows current spend and forecast. Lower the limit below current spend and confirm an email alert and a Pub/Sub message are produced. Confirm the subscribed function runs.

Next Steps

Adopt resource labels for granular cost allocation, export billing data to BigQuery for analysis, and set budgets per environment (dev, staging, prod).

Prerequisites

  • Google Cloud billing account
  • gcloud CLI installed
  • Terraform installed

Steps

  • 1
    Identify the billing account
  • 2
    Create a budget
  • 3
    Add threshold rules
  • 4
    Scope to projects
  • 5
    Publish to Pub/Sub
  • 6
    Automate a response

Category

Finops