Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource: google_billing_budget #2734

Merged
merged 9 commits into from
Dec 3, 2019
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
187 changes: 187 additions & 0 deletions products/billingbudget/api.yaml
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
danawillow marked this conversation as resolved.
Show resolved Hide resolved
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
umairidris marked this conversation as resolved.
Show resolved Hide resolved
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.
umairidris marked this conversation as resolved.
Show resolved Hide resolved
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
umairidris marked this conversation as resolved.
Show resolved Hide resolved
accepted. It represents the JSON schema as defined in
https://cloud.google.com/billing/docs/how-to/budgets#notification_format.
48 changes: 48 additions & 0 deletions products/billingbudget/terraform.yaml
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
umairidris marked this conversation as resolved.
Show resolved Hide resolved
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)) -%>
19 changes: 19 additions & 0 deletions templates/terraform/examples/billing_budget_basic.tf.erb
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'] -%>"
umairidris marked this conversation as resolved.
Show resolved Hide resolved
}

resource "google_billing_budget" "<%= ctx[:primary_resource_id] %>" {
umairidris marked this conversation as resolved.
Show resolved Hide resolved
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
}
}
31 changes: 31 additions & 0 deletions templates/terraform/examples/billing_budget_filter.tf.erb
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"
}
}
6 changes: 6 additions & 0 deletions third_party/terraform/website-compiled/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@
</li>
<li<%%= sidebar_current("docs-google-billing-account-iam-policy") %>>
<a href="/docs/providers/google/r/google_billing_account_iam_policy.html">google_billing_account_iam_policy</a>
</li>
<% unless version == 'ga' -%>
<li<%%= sidebar_current("docs-google-billing-budget") %>>
<a href="/docs/providers/google/r/billing_budget.html">google_billing_budget</a>
</li>
<% end -%>
<li<%%= sidebar_current("docs-google-folder-x") %>>
<a href="/docs/providers/google/r/google_folder.html">google_folder</a>
</li>
Expand Down