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
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"
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"
resource "google_billing_budget" "budget" {
provider = google-beta
billing_account = data.google_billing_account.account.id
display_name = var.budget_name
budget_filter {
Parameters
-
billing_accountrequired - string
ID of the billing account to set a budget on.
-
display_nameoptional - string
User data for display name in UI. Must be <= 60 chars.
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_rulelist block-
disable_default_iam_recipientsoptional - bool
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.
-
monitoring_notification_channelsoptional - list of string
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.
-
pubsub_topicoptional - string
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.
-
schema_versionoptional - string
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.
-
-
amountlist block-
last_period_amountoptional - bool
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_amountlist block-
currency_codeoptional computed - string
The 3-letter currency code defined in ISO 4217.
-
nanosoptional - number
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.
-
unitsoptional - string
The whole units of the amount. For example if currencyCode is "USD", then 1 unit is one US dollar.
-
-
-
budget_filterlist block-
credit_typesoptional computed - list of string
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.
-
credit_types_treatmentoptional - string
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"]
-
labelsoptional 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.
-
projectsoptional - list of string
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.
-
servicesoptional 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.
-
subaccountsoptional computed - list of string
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_ruleslist block-
spend_basisoptional - string
The type of basis used to determine if spend has passed the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", "FORECASTED_SPEND"]
-
threshold_percentrequired - number
Send an alert when this threshold is exceeded. This is a 1.0-based percentage, so 0.5 = 50%. Must be >= 0.
-
-
timeoutssingle 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_projectand setuser_project_overrideto true in the provider configuration. Otherwise the Billing Budgets API will return a 403 error. Your account must have theserviceusage.services.usepermission on thebilling_projectyou 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.