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

Made deletion of all budget filter projects be recognized #4731

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mmv1/products/billingbudget/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ objects:
- !ruby/object:Api::Resource
name: Budget
base_url: billingAccounts/{{billing_account}}/budgets
self_link: '{{name}}'
self_link: 'billingAccounts/{{billing_account}}/budgets/{{name}}'
melinath marked this conversation as resolved.
Show resolved Hide resolved
update_verb: :PATCH
# TODO: investigate why updates are not being handled by the API when this
# is enabled.
# update_mask: true
update_mask: true
description: |
Budget configuration for a billing account.
references: !ruby/object:Api::Resource::ReferenceLinks
Expand Down
15 changes: 6 additions & 9 deletions mmv1/products/billingbudget/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
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.
id_format: '{{name}}'
exclude_import: true
id_format: 'billingAccounts/{{billing_account}}/budgets/{{name}}'
import_format: ["billingAccounts/{{billing_account}}/budgets/{{name}}", "{{name}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: 'billing_budget_basic'
Expand All @@ -31,23 +31,20 @@ overrides: !ruby/object:Overrides::ResourceOverrides
display_name: 'Example Billing Budget'
test_env_vars:
billing_acct: :BILLING_ACCT
skip_import_test: true
- !ruby/object:Provider::Terraform::Examples
name: 'billing_budget_lastperiod'
primary_resource_id: 'budget'
vars:
display_name: 'Example Billing Budget'
test_env_vars:
billing_acct: :BILLING_ACCT
skip_import_test: true
- !ruby/object:Provider::Terraform::Examples
name: 'billing_budget_filter'
primary_resource_id: 'budget'
vars:
display_name: 'Example Billing Budget'
test_env_vars:
billing_acct: :BILLING_ACCT
skip_import_test: true
- !ruby/object:Provider::Terraform::Examples
name: 'billing_budget_notify'
primary_resource_id: 'budget'
Expand All @@ -56,17 +53,17 @@ overrides: !ruby/object:Overrides::ResourceOverrides
channel_name: 'Example Notification Channel'
test_env_vars:
billing_acct: :BILLING_ACCT
skip_import_test: true
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:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
allUpdatesRule.schemaVersion: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: templates/terraform/custom_flatten/default_if_empty.erb
budgetFilter.creditTypes: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
budgetFilter: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
update_mask_fields:
- "budgetFilter.projects"
budgetFilter.services: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
budgetFilter.subaccounts: !ruby/object:Overrides::Terraform::PropertyOverride
Expand Down
103 changes: 103 additions & 0 deletions mmv1/third_party/terraform/tests/resource_billing_budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,106 @@ resource "google_billing_budget" "budget" {
}
`, context)
}

func TestAccBillingBudget_billingBudgetUpdateRemoveFilter(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"billing_acct": getTestBillingAccountFromEnv(t),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBillingBudget_billingBudgetUpdateRemoveFilterStart(context),
},
{
ResourceName: "google_billing_budget.budget",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccBillingBudget_billingBudgetUpdateRemoveFilterEnd(context),
},
{
ResourceName: "google_billing_budget.budget",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccBillingBudget_billingBudgetUpdateRemoveFilterStart(context map[string]interface{}) string {
return Nprintf(`
data "google_billing_account" "account" {
billing_account = "%{billing_acct}"
}

data "google_project" "project" {
}

resource "google_billing_budget" "budget" {
billing_account = data.google_billing_account.account.id
display_name = "Example Billing Budget%{random_suffix}"

budget_filter {
projects = ["projects/${data.google_project.project.number}"]
}

amount {
specified_amount {
currency_code = "USD"
units = "100000"
}
}

threshold_rules {
threshold_percent = 0.5
}
threshold_rules {
threshold_percent = 0.9
spend_basis = "FORECASTED_SPEND"
}
}
`, context)
}

func testAccBillingBudget_billingBudgetUpdateRemoveFilterEnd(context map[string]interface{}) string {
return Nprintf(`
data "google_billing_account" "account" {
billing_account = "%{billing_acct}"
}

data "google_project" "project" {
}

resource "google_billing_budget" "budget" {
billing_account = data.google_billing_account.account.id
display_name = "Example Billing Budget%{random_suffix}"

budget_filter {
projects = []
}

amount {
specified_amount {
currency_code = "USD"
units = "100000"
}
}

threshold_rules {
threshold_percent = 0.5
}
threshold_rules {
threshold_percent = 0.9
spend_basis = "FORECASTED_SPEND"
}
}
`, context)
}