Google Cloud Billing Budget

This page shows how to write Terraform for Cloud Billing Budget and write them securely.

google_billing_budget (Terraform)

The Budget in Cloud Billing can be configured in Terraform with the resource name google_billing_budget. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

alert.tf#L4
resource "google_billing_budget" "this" {
  billing_account = data.google_billing_account.account.id
  display_name    = "GCP Budget Alert"

  budget_filter {
    credit_types_treatment = "INCLUDE_ALL_CREDITS"
budget.tf#L8
resource "google_billing_budget" "budget" {
  provider = google-beta
  depends_on = [google_project_service.gcp_services]

  billing_account = data.google_billing_account.account.id
  display_name = "Budget Keeper Budget"
budget.tf#L6
resource "google_billing_budget" "budget" {
  provider = google-beta
  billing_account = data.google_billing_account.account.id
  display_name = var.budget_name

  budget_filter {

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

ID of the billing account to set a budget on.

User data for display name in UI. Must be <= 60 chars.

  • id optional computed - string
  • name optional computed - string

Resource name of the budget. The resource name implies the scope of a budget. Values are of the form billingAccounts/[billingAccountId]/budgets/[budgetId].

  • all_updates_rule list block

    Boolean. When set to true, disables default notifications sent when a threshold is exceeded. Default recipients are those with Billing Account Administrators and Billing Account Users IAM roles for the target account.

    The full resource name of a monitoring notification channel in the form projects/[project_id]/notificationChannels/[channel_id]. A maximum of 5 channels are allowed.

    The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form projects/[project_id]/topics/[topic_id]. Updates are sent at regular intervals to the topic.

    The schema version of the notification. Only "1.0" is accepted. It represents the JSON schema as defined in https://cloud.google.com/billing/docs/how-to/budgets#notification_format.

  • amount list block

    Configures a budget amount that is automatically set to 100% of last period's spend. Boolean. Set value to true to use. Do not set to false, instead use the 'specified_amount' block.

    • specified_amount list block

      The 3-letter currency code defined in ISO 4217.

      Number of nano (10^-9) units of the amount. The value must be between -999,999,999 and +999,999,999 inclusive. If units is positive, nanos must be positive or zero. If units is zero, nanos can be positive, zero, or negative. If units is negative, nanos must be negative or zero. For example $-1.75 is represented as units=-1 and nanos=-750,000,000.

      The whole units of the amount. For example if currencyCode is "USD", then 1 unit is one US dollar.

  • budget_filter list block

    A set of subaccounts of the form billingAccounts/[account_id], specifying that usage from only this set of subaccounts should be included in the budget. If a subaccount is set to the name of the parent account, usage from the parent account will be included. If the field is omitted, the report will include usage from the parent account and all subaccounts, if they exist.

    Specifies how credits should be treated when determining spend for threshold calculations. Default value: "INCLUDE_ALL_CREDITS" Possible values: ["INCLUDE_ALL_CREDITS", "EXCLUDE_ALL_CREDITS", "INCLUDE_SPECIFIED_CREDITS"]

    • labels optional computed - map from string to string

    A single label and value pair specifying that usage from only this set of labeled resources should be included in the budget.

    A set of projects of the form projects/[project_number], specifying that usage from only this set of projects should be included in the budget. If omitted, the report will include all usage for the billing account, regardless of which project the usage occurred on.

    • services optional computed - list of string

    A set of services of the form services/[service_id], specifying that usage from only this set of services should be included in the budget. If omitted, the report will include usage for all the services. The service names are available through the Catalog API: https://cloud.google.com/billing/v1/how-tos/catalog-api.

    A set of subaccounts of the form billingAccounts/[account_id], specifying that usage from only this set of subaccounts should be included in the budget. If a subaccount is set to the name of the parent account, usage from the parent account will be included. If the field is omitted, the report will include usage from the parent account and all subaccounts, if they exist.

  • threshold_rules list block

    The type of basis used to determine if spend has passed the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", "FORECASTED_SPEND"]

    Send an alert when this threshold is exceeded. This is a 1.0-based percentage, so 0.5 = 50%. Must be >= 0.

  • timeouts single block

Explanation in Terraform Registry

Budget configuration for a billing account. To get more information about Budget, see:

  • API documentation
  • How-to Guides
    • Creating a budget

      Warning: If you are using User ADCs (Application Default Credentials) with this resource, you must specify a billing_project and set user_project_override to true in the provider configuration. Otherwise the Billing Budgets API will return a 403 error. Your account must have the serviceusage.services.use permission on the billing_project you defined.

Frequently asked questions

What is Google Cloud Billing Budget?

Google Cloud Billing Budget is a resource for Cloud Billing of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud Billing Budget?

For Terraform, the mintak21/terraform, glipecki/gcp-budget-keeper and ekalachev/BigData source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.