-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resource: google_billing_budget (#2734)
Merged PR #2734.
- Loading branch information
1 parent
21bd9c4
commit c3d14b2
Showing
7 changed files
with
293 additions
and
2 deletions.
There are no files selected for viewing
Submodule terraform
updated
from c20575 to b9b3d1
Submodule terraform-beta
updated
from dd21b9 to b57462
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
# Copyright 2019 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Api::Product | ||
name: Billing | ||
display_name: Billing Budget | ||
versions: | ||
- !ruby/object:Api::Product::Version | ||
name: beta | ||
base_url: https://billingbudgets.googleapis.com/v1beta1/ | ||
scopes: | ||
- https://www.googleapis.com/auth/cloud-platform | ||
apis_required: | ||
- !ruby/object:Api::Product::ApiReference | ||
name: Billing Budget | ||
url: https://console.cloud.google.com/apis/library/billingbudgets.googleapis.com/ | ||
objects: | ||
- !ruby/object:Api::Resource | ||
name: Budget | ||
base_url: billingAccounts/{{billing_account}}/budgets | ||
self_link: '{{name}}' | ||
update_verb: :PATCH | ||
# TODO: investigate why updates are not being handled by the API when this | ||
# is enabled. | ||
# update_mask: true | ||
description: | | ||
Budget configuration for a billing account. | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
guides: | ||
'Creating a budget': | ||
'https://cloud.google.com/billing/docs/how-to/budgets' | ||
api: 'https://cloud.google.com/billing/docs/reference/budget/rest/v1beta1/billingAccounts.budgets' | ||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: billingAccount | ||
description: | | ||
ID of the billing account to set a budget on. | ||
required: true | ||
input: true | ||
url_param_only: true | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: name | ||
description: | | ||
Resource name of the budget. The resource name | ||
implies the scope of a budget. Values are of the form | ||
billingAccounts/{billingAccountId}/budgets/{budgetId}. | ||
output: true | ||
- !ruby/object:Api::Type::NestedObject | ||
name: budget | ||
required: true | ||
description: | | ||
The budget to create. | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: displayName | ||
description: | | ||
User data for display name in UI. Must be <= 60 chars. | ||
- !ruby/object:Api::Type::NestedObject | ||
name: budgetFilter | ||
description: | | ||
Filters that define which resources are used to compute the actual | ||
spend against the budget. | ||
at_least_one_of: | ||
- budget_filter.0.projects | ||
- budget_filter.0.credit_types_treatment | ||
- budget_filter.0.services | ||
properties: | ||
- !ruby/object:Api::Type::Array | ||
name: projects | ||
description: | | ||
A set of projects of the form projects/{project_id}, | ||
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. Only zero or one project can be | ||
specified currently. | ||
item_type: Api::Type::String | ||
- !ruby/object:Api::Type::Enum | ||
name: creditTypesTreatment | ||
description: | | ||
Specifies how credits should be treated when determining spend | ||
for threshold calculations. | ||
default_value: :INCLUDE_ALL_CREDITS | ||
values: | ||
- :INCLUDE_ALL_CREDITS | ||
- :EXCLUDE_ALL_CREDITS | ||
- !ruby/object:Api::Type::Array | ||
name: services | ||
description: | | ||
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. | ||
item_type: Api::Type::String | ||
- !ruby/object:Api::Type::NestedObject | ||
name: amount | ||
required: true | ||
description: | | ||
The budgeted amount for each usage period. | ||
properties: | ||
- !ruby/object:Api::Type::NestedObject | ||
name: specifiedAmount | ||
description: | | ||
A specified amount to use as the budget. currencyCode is | ||
optional. If specified, it must match the currency of the | ||
billing account. The currencyCode is provided on output. | ||
required: true | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: currencyCode | ||
description: | | ||
The 3-letter currency code defined in ISO 4217. | ||
- !ruby/object:Api::Type::String | ||
name: units | ||
description: | | ||
The whole units of the amount. For example if currencyCode | ||
is "USD", then 1 unit is one US dollar. | ||
- !ruby/object:Api::Type::Integer | ||
name: nanos | ||
description: | | ||
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. | ||
- !ruby/object:Api::Type::Array | ||
name: thresholdRules | ||
required: true | ||
description: | | ||
Rules that trigger alerts (notifications of thresholds being | ||
crossed) when spend exceeds the specified percentages of the | ||
budget. | ||
item_type: !ruby/object:Api::Type::NestedObject | ||
properties: | ||
- !ruby/object:Api::Type::Double | ||
name: thresholdPercent | ||
required: true | ||
description: | | ||
Send an alert when this threshold is exceeded. This is a | ||
1.0-based percentage, so 0.5 = 50%. Must be >= 0. | ||
send_empty_value: true | ||
- !ruby/object:Api::Type::Enum | ||
name: spendBasis | ||
description: | | ||
The type of basis used to determine if spend has passed | ||
the threshold. | ||
default_value: :CURRENT_SPEND | ||
values: | ||
- :CURRENT_SPEND | ||
- :FORECASTED_SPEND | ||
- !ruby/object:Api::Type::NestedObject | ||
name: allUpdatesRule | ||
description: | | ||
Defines notifications that are sent on every update to the | ||
billing account's spend, regardless of the thresholds defined | ||
using threshold rules. | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: pubsubTopic | ||
required: true | ||
description: | | ||
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. | ||
- !ruby/object:Api::Type::String | ||
name: schemaVersion | ||
default_value: "1.0" | ||
description: | | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2019 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Provider::Terraform::Config | ||
overrides: !ruby/object:Overrides::ResourceOverrides | ||
Budget: !ruby/object:Overrides::Terraform::ResourceOverride | ||
id_format: '{{name}}' | ||
import_format: ['{{name}}'] | ||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'billing_budget_basic' | ||
min_version: beta | ||
primary_resource_id: 'budget' | ||
vars: | ||
display_name: 'Example Billing Budget' | ||
test_env_vars: | ||
billing_acct: :BILLING_ACCT | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'billing_budget_filter' | ||
min_version: beta | ||
primary_resource_id: 'budget' | ||
vars: | ||
display_name: 'Example Billing Budget' | ||
test_env_vars: | ||
billing_acct: :BILLING_ACCT | ||
custom_code: !ruby/object:Provider::Terraform::CustomCode | ||
custom_import: templates/terraform/custom_import/self_link_as_name.erb | ||
post_create: templates/terraform/post_create/set_computed_name.erb | ||
properties: | ||
budget: !ruby/object:Overrides::Terraform::PropertyOverride | ||
flatten_object: true | ||
|
||
# This is for copying files over | ||
files: !ruby/object:Provider::Config::Files | ||
# These files have templating (ERB) code that will be run. | ||
# This is usually to add licensing info, autogeneration notices, etc. | ||
compile: | ||
<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
data "google_billing_account" "account" { | ||
provider = google-beta | ||
billing_account = "<%= ctx[:test_env_vars]['billing_acct'] -%>" | ||
} | ||
|
||
resource "google_billing_budget" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
billing_account = data.google_billing_account.account.id | ||
display_name = "<%= ctx[:vars]['display_name'] %>" | ||
amount { | ||
specified_amount { | ||
currency_code = "USD" | ||
units = "100000" | ||
} | ||
} | ||
threshold_rules { | ||
threshold_percent = 0.5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
data "google_billing_account" "account" { | ||
provider = google-beta | ||
billing_account = "<%= ctx[:test_env_vars]['billing_acct'] -%>" | ||
} | ||
|
||
resource "google_billing_budget" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
billing_account = data.google_billing_account.account.id | ||
display_name = "<%= ctx[:vars]['display_name'] %>" | ||
|
||
budget_filter { | ||
projects = ["projects/example-project"] | ||
credit_types_treatment = "EXCLUDE_ALL_CREDITS" | ||
services = ["services/24E6-581D-38E5"] # Bigquery | ||
} | ||
|
||
amount { | ||
specified_amount { | ||
currency_code = "USD" | ||
units = "100000" | ||
} | ||
} | ||
|
||
threshold_rules { | ||
threshold_percent = 0.5 | ||
} | ||
threshold_rules { | ||
threshold_percent = 0.9 | ||
spend_basis = "FORECASTED_SPEND" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters