1// Copyright 2023 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15syntax = "proto3"; 16 17package google.cloud.billing.budgets.v1; 18 19import "google/api/field_behavior.proto"; 20import "google/api/resource.proto"; 21import "google/protobuf/struct.proto"; 22import "google/type/date.proto"; 23import "google/type/money.proto"; 24 25option go_package = "cloud.google.com/go/billing/budgets/apiv1/budgetspb;budgetspb"; 26option java_multiple_files = true; 27option java_outer_classname = "BudgetModelProto"; 28option java_package = "com.google.cloud.billing.budgets.v1"; 29 30// A budget is a plan that describes what you expect to spend on Cloud 31// projects, plus the rules to execute as spend is tracked against that plan, 32// (for example, send an alert when 90% of the target spend is met). 33// The budget time period is configurable, with options such as month (default), 34// quarter, year, or custom time period. 35message Budget { 36 option (google.api.resource) = { 37 type: "billingbudgets.googleapis.com/Budget" 38 pattern: "billingAccounts/{billing_account}/budgets/{budget}" 39 }; 40 41 // Output only. Resource name of the budget. 42 // The resource name implies the scope of a budget. Values are of the form 43 // `billingAccounts/{billingAccountId}/budgets/{budgetId}`. 44 string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; 45 46 // User data for display name in UI. The name must be less than or equal to 60 47 // characters. 48 string display_name = 2; 49 50 // Optional. Filters that define which resources are used to compute the 51 // actual spend against the budget amount, such as projects, services, and the 52 // budget's time period, as well as other filters. 53 Filter budget_filter = 3 [(google.api.field_behavior) = OPTIONAL]; 54 55 // Required. Budgeted amount. 56 BudgetAmount amount = 4 [(google.api.field_behavior) = REQUIRED]; 57 58 // Optional. Rules that trigger alerts (notifications of thresholds 59 // being crossed) when spend exceeds the specified percentages of the budget. 60 // 61 // Optional for `pubsubTopic` notifications. 62 // 63 // Required if using email notifications. 64 repeated ThresholdRule threshold_rules = 5 65 [(google.api.field_behavior) = OPTIONAL]; 66 67 // Optional. Rules to apply to notifications sent based on budget spend and 68 // thresholds. 69 NotificationsRule notifications_rule = 6 70 [(google.api.field_behavior) = OPTIONAL]; 71 72 // Optional. Etag to validate that the object is unchanged for a 73 // read-modify-write operation. 74 // An empty etag causes an update to overwrite other changes. 75 string etag = 7 [(google.api.field_behavior) = OPTIONAL]; 76} 77 78// The budgeted amount for each usage period. 79message BudgetAmount { 80 // Specification for what amount to use as the budget. 81 oneof budget_amount { 82 // A specified amount to use as the budget. 83 // `currency_code` is optional. If specified when creating a budget, it must 84 // match the currency of the billing account. If specified when updating a 85 // budget, it must match the currency_code of the existing budget. 86 // The `currency_code` is provided on output. 87 google.type.Money specified_amount = 1; 88 89 // Use the last period's actual spend as the budget for the present period. 90 // LastPeriodAmount can only be set when the budget's time period is a 91 // [Filter.calendar_period][google.cloud.billing.budgets.v1.Filter.calendar_period]. 92 // It cannot be set in combination with 93 // [Filter.custom_period][google.cloud.billing.budgets.v1.Filter.custom_period]. 94 LastPeriodAmount last_period_amount = 2; 95 } 96} 97 98// Describes a budget amount targeted to the last 99// [Filter.calendar_period][google.cloud.billing.budgets.v1.Filter.calendar_period] 100// spend. At this time, the amount is automatically 100% of the last calendar 101// period's spend; that is, there are no other options yet. 102// LastPeriodAmount cannot be set for a budget configured with 103// a 104// [Filter.custom_period][google.cloud.billing.budgets.v1.Filter.custom_period]. 105message LastPeriodAmount {} 106 107// ThresholdRule contains the definition of a threshold. Threshold rules define 108// the triggering events used to generate a budget notification email. When a 109// threshold is crossed (spend exceeds the specified percentages of the 110// budget), budget alert emails are sent to the email recipients you specify 111// in the 112// [NotificationsRule](#notificationsrule). 113// 114// Threshold rules also affect the fields included in the 115// [JSON data 116// object](https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format) 117// sent to a Pub/Sub topic. 118// 119// Threshold rules are _required_ if using email notifications. 120// 121// Threshold rules are _optional_ if only setting a 122// [`pubsubTopic` NotificationsRule](#NotificationsRule), 123// unless you want your JSON data object to include data about the thresholds 124// you set. 125// 126// For more information, see 127// [set budget threshold rules and 128// actions](https://cloud.google.com/billing/docs/how-to/budgets#budget-actions). 129message ThresholdRule { 130 // The type of basis used to determine if spend has passed the threshold. 131 enum Basis { 132 // Unspecified threshold basis. 133 BASIS_UNSPECIFIED = 0; 134 135 // Use current spend as the basis for comparison against the threshold. 136 CURRENT_SPEND = 1; 137 138 // Use forecasted spend for the period as the basis for comparison against 139 // the threshold. 140 // FORECASTED_SPEND can only be set when the budget's time period is a 141 // [Filter.calendar_period][google.cloud.billing.budgets.v1.Filter.calendar_period]. 142 // It cannot be set in combination with 143 // [Filter.custom_period][google.cloud.billing.budgets.v1.Filter.custom_period]. 144 FORECASTED_SPEND = 2; 145 } 146 147 // Required. Send an alert when this threshold is exceeded. 148 // This is a 1.0-based percentage, so 0.5 = 50%. 149 // Validation: non-negative number. 150 double threshold_percent = 1 [(google.api.field_behavior) = REQUIRED]; 151 152 // Optional. The type of basis used to determine if spend has passed the 153 // threshold. Behavior defaults to CURRENT_SPEND if not set. 154 Basis spend_basis = 2 [(google.api.field_behavior) = OPTIONAL]; 155} 156 157// NotificationsRule defines notifications that are sent based on budget spend 158// and thresholds. 159message NotificationsRule { 160 // Optional. The name of the Pub/Sub topic where budget-related messages are 161 // published, in the form `projects/{project_id}/topics/{topic_id}`. Updates 162 // are sent to the topic at regular intervals; the timing of the updates is 163 // not dependent on the [threshold rules](#thresholdrule) you've set. 164 // 165 // Note that if you want your 166 // [Pub/Sub JSON 167 // object](https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format) 168 // to contain data for `alertThresholdExceeded`, you need at least one 169 // [alert threshold rule](#thresholdrule). When you set threshold rules, you 170 // must also enable at least one of the email notification options, either 171 // using the default IAM recipients or Cloud Monitoring email notification 172 // channels. 173 // 174 // To use Pub/Sub topics with budgets, you must do the following: 175 // 176 // 1. Create the Pub/Sub topic 177 // before connecting it to your budget. For guidance, see 178 // [Manage programmatic budget alert 179 // notifications](https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications). 180 // 181 // 2. Grant the API caller the `pubsub.topics.setIamPolicy` permission on 182 // the Pub/Sub topic. If not set, the API call fails with PERMISSION_DENIED. 183 // For additional details on Pub/Sub roles and permissions, see 184 // [Permissions required for this 185 // task](https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#permissions_required_for_this_task). 186 string pubsub_topic = 1 [(google.api.field_behavior) = OPTIONAL]; 187 188 // Optional. Required when 189 // [NotificationsRule.pubsub_topic][google.cloud.billing.budgets.v1.NotificationsRule.pubsub_topic] 190 // is set. The schema version of the notification sent to 191 // [NotificationsRule.pubsub_topic][google.cloud.billing.budgets.v1.NotificationsRule.pubsub_topic]. 192 // Only "1.0" is accepted. It represents the JSON schema as defined in 193 // https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format. 194 string schema_version = 2 [(google.api.field_behavior) = OPTIONAL]; 195 196 // Optional. Email targets to send notifications to when a threshold is 197 // exceeded. This is in addition to the `DefaultIamRecipients` who receive 198 // alert emails based on their billing account IAM role. The value is the full 199 // REST resource name of a Cloud Monitoring email notification channel with 200 // the form `projects/{project_id}/notificationChannels/{channel_id}`. A 201 // maximum of 5 email notifications are allowed. 202 // 203 // To customize budget alert email recipients with monitoring notification 204 // channels, you _must create the monitoring notification channels before 205 // you link them to a budget_. For guidance on setting up notification 206 // channels to use with budgets, see 207 // [Customize budget alert email 208 // recipients](https://cloud.google.com/billing/docs/how-to/budgets-notification-recipients). 209 // 210 // For Cloud Billing budget alerts, you _must use email notification 211 // channels_. The other types of notification channels are _not_ 212 // supported, such as Slack, SMS, or PagerDuty. If you want to 213 // [send budget notifications to 214 // Slack](https://cloud.google.com/billing/docs/how-to/notify#send_notifications_to_slack), 215 // use a pubsubTopic and configure 216 // [programmatic 217 // notifications](https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications). 218 repeated string monitoring_notification_channels = 3 219 [(google.api.field_behavior) = OPTIONAL]; 220 221 // Optional. When set to true, disables default notifications sent when a 222 // threshold is exceeded. Default notifications are sent to those with Billing 223 // Account Administrator and Billing Account User IAM roles for the target 224 // account. 225 bool disable_default_iam_recipients = 4 226 [(google.api.field_behavior) = OPTIONAL]; 227 228 // Optional. When set to true, and when the budget has a single project 229 // configured, notifications will be sent to project level recipients of that 230 // project. This field will be ignored if the budget has multiple or no 231 // project configured. 232 // 233 // Currently, project level recipients are the users with `Owner` role on a 234 // cloud project. 235 bool enable_project_level_recipients = 5 236 [(google.api.field_behavior) = OPTIONAL]; 237} 238 239// A filter for a budget, limiting the scope of the cost to calculate. 240message Filter { 241 // Specifies how credits are applied when determining the spend for 242 // threshold calculations. Budgets track the total cost minus any applicable 243 // selected credits. 244 // [See the documentation for a list of credit 245 // types](https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#credits-type). 246 enum CreditTypesTreatment { 247 CREDIT_TYPES_TREATMENT_UNSPECIFIED = 0; 248 249 // All types of credit are subtracted from the gross cost to determine the 250 // spend for threshold calculations. 251 INCLUDE_ALL_CREDITS = 1; 252 253 // All types of credit are added to the net cost to determine the spend for 254 // threshold calculations. 255 EXCLUDE_ALL_CREDITS = 2; 256 257 // [Credit 258 // types](https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#credits-type) 259 // specified in the credit_types field are subtracted from the 260 // gross cost to determine the spend for threshold calculations. 261 INCLUDE_SPECIFIED_CREDITS = 3; 262 } 263 264 // Optional. A set of projects of the form `projects/{project}`, 265 // specifying that usage from only this set of projects should be 266 // included in the budget. If omitted, the report includes all usage for 267 // the billing account, regardless of which project the usage occurred on. 268 repeated string projects = 1 [(google.api.field_behavior) = OPTIONAL]; 269 270 // Optional. A set of folder and organization names of the form 271 // `folders/{folderId}` or `organizations/{organizationId}`, specifying that 272 // usage from only this set of folders and organizations should be included in 273 // the budget. If omitted, the budget includes all usage that the billing 274 // account pays for. If the folder or organization contains projects that are 275 // paid for by a different Cloud Billing account, the budget *doesn't* apply 276 // to those projects. 277 repeated string resource_ancestors = 2 278 [(google.api.field_behavior) = OPTIONAL]; 279 280 // Optional. If 281 // [Filter.credit_types_treatment][google.cloud.billing.budgets.v1.Filter.credit_types_treatment] 282 // is INCLUDE_SPECIFIED_CREDITS, this is a list of credit types to be 283 // subtracted from gross cost to determine the spend for threshold 284 // calculations. See [a list of acceptable credit type 285 // values](https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#credits-type). 286 // 287 // If 288 // [Filter.credit_types_treatment][google.cloud.billing.budgets.v1.Filter.credit_types_treatment] 289 // is **not** INCLUDE_SPECIFIED_CREDITS, this field must be empty. 290 repeated string credit_types = 7 [(google.api.field_behavior) = OPTIONAL]; 291 292 // Optional. If not set, default behavior is `INCLUDE_ALL_CREDITS`. 293 CreditTypesTreatment credit_types_treatment = 4 294 [(google.api.field_behavior) = OPTIONAL]; 295 296 // Optional. A set of services of the form `services/{service_id}`, 297 // specifying that usage from only this set of services should be 298 // included in the budget. If omitted, the report includes usage for 299 // all the services. 300 // The service names are available through the Catalog API: 301 // https://cloud.google.com/billing/v1/how-tos/catalog-api. 302 repeated string services = 3 [(google.api.field_behavior) = OPTIONAL]; 303 304 // Optional. A set of subaccounts of the form `billingAccounts/{account_id}`, 305 // specifying that usage from only this set of subaccounts should be included 306 // in the budget. If a subaccount is set to the name of the parent account, 307 // usage from the parent account is included. If the field is omitted, 308 // the report includes usage from the parent account and all subaccounts, 309 // if they exist. 310 repeated string subaccounts = 5 [(google.api.field_behavior) = OPTIONAL]; 311 312 // Optional. A single label and value pair specifying that usage from only 313 // this set of labeled resources should be included in the budget. If omitted, 314 // the report includes all labeled and unlabeled usage. 315 // 316 // An object containing a single `"key": value` pair. Example: `{ "name": 317 // "wrench" }`. 318 // 319 // _Currently, multiple entries or multiple values per entry are not 320 // allowed._ 321 map<string, google.protobuf.ListValue> labels = 6 322 [(google.api.field_behavior) = OPTIONAL]; 323 324 // Multiple options to choose the budget's time period, specifying that only 325 // usage that occurs during this time period should be included in the budget. 326 // If not set, the <code>usage_period</code> defaults to CalendarPeriod.MONTH. 327 oneof usage_period { 328 // Optional. Specifies to track usage for recurring calendar period. 329 // For example, assume that CalendarPeriod.QUARTER is set. The budget 330 // tracks usage from April 1 to June 30, when the current calendar month is 331 // April, May, June. After that, it tracks usage from July 1 to 332 // September 30 when the current calendar month is July, August, September, 333 // so on. 334 CalendarPeriod calendar_period = 8 [(google.api.field_behavior) = OPTIONAL]; 335 336 // Optional. Specifies to track usage from any start date (required) to any 337 // end date (optional). This time period is static, it does not recur. 338 CustomPeriod custom_period = 9 [(google.api.field_behavior) = OPTIONAL]; 339 } 340} 341 342// All date times begin at 12 AM US and Canadian Pacific Time (UTC-8). 343message CustomPeriod { 344 // Required. The start date must be after January 1, 2017. 345 google.type.Date start_date = 1 [(google.api.field_behavior) = REQUIRED]; 346 347 // Optional. The end date of the time period. Budgets with elapsed end date 348 // won't be processed. If unset, specifies to track all usage incurred since 349 // the start_date. 350 google.type.Date end_date = 2 [(google.api.field_behavior) = OPTIONAL]; 351} 352 353// A `CalendarPeriod` represents the abstract concept of a time period that 354// has a canonical start. Grammatically, "the start of the current 355// `CalendarPeriod`". All calendar times begin at 12 AM US and Canadian 356// Pacific Time (UTC-8). 357enum CalendarPeriod { 358 // Calendar period is unset. This is the default if the budget is for a 359 // custom time period (CustomPeriod). 360 CALENDAR_PERIOD_UNSPECIFIED = 0; 361 362 // A month. Month starts on the first day of each month, such as January 1, 363 // February 1, March 1, and so on. 364 MONTH = 1; 365 366 // A quarter. Quarters start on dates January 1, April 1, July 1, and October 367 // 1 of each year. 368 QUARTER = 2; 369 370 // A year. Year starts on January 1. 371 YEAR = 3; 372} 373