From 257f11af612356d304d384c13eff619a0326035b Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 29 Jun 2021 21:25:51 +0000 Subject: [PATCH] Made billing budget amount updatable (#4929) * Added test reproducing the error * Added amount subfields to update mask Signed-off-by: Modular Magician --- .changelog/4929.txt | 3 ++ google/resource_billing_budget.go | 4 +- google/resource_billing_budget_test.go | 53 +++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 .changelog/4929.txt diff --git a/.changelog/4929.txt b/.changelog/4929.txt new file mode 100644 index 00000000000..c21756460d1 --- /dev/null +++ b/.changelog/4929.txt @@ -0,0 +1,3 @@ +```release-note:bug +billing: made `amount.specified_amount.units` updatable on `google_billing_budget` +``` diff --git a/google/resource_billing_budget.go b/google/resource_billing_budget.go index 7a30853f808..5510fd58556 100644 --- a/google/resource_billing_budget.go +++ b/google/resource_billing_budget.go @@ -471,7 +471,9 @@ func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("amount") { - updateMask = append(updateMask, "amount") + updateMask = append(updateMask, "amount.specifiedAmount.currencyCode", + "amount.specifiedAmount.units", + "amount.specifiedAmount.nanos") } if d.HasChange("threshold_rules") { diff --git a/google/resource_billing_budget_test.go b/google/resource_billing_budget_test.go index 9b09bd92873..12958bbce66 100644 --- a/google/resource_billing_budget_test.go +++ b/google/resource_billing_budget_test.go @@ -62,7 +62,7 @@ resource "google_billing_budget" "budget" { `, context) } -func TestAccBillingBudget_billingBudgetUpdateRemoveFilter(t *testing.T) { +func TestAccBillingBudget_billingBudgetUpdate(t *testing.T) { t.Parallel() context := map[string]interface{}{ @@ -76,7 +76,7 @@ func TestAccBillingBudget_billingBudgetUpdateRemoveFilter(t *testing.T) { CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccBillingBudget_billingBudgetUpdateRemoveFilterStart(context), + Config: testAccBillingBudget_billingBudgetUpdateStart(context), }, { ResourceName: "google_billing_budget.budget", @@ -84,7 +84,15 @@ func TestAccBillingBudget_billingBudgetUpdateRemoveFilter(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccBillingBudget_billingBudgetUpdateRemoveFilterEnd(context), + Config: testAccBillingBudget_billingBudgetUpdateRemoveFilter(context), + }, + { + ResourceName: "google_billing_budget.budget", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBillingBudget_billingBudgetUpdateChangeAmount(context), }, { ResourceName: "google_billing_budget.budget", @@ -95,7 +103,7 @@ func TestAccBillingBudget_billingBudgetUpdateRemoveFilter(t *testing.T) { }) } -func testAccBillingBudget_billingBudgetUpdateRemoveFilterStart(context map[string]interface{}) string { +func testAccBillingBudget_billingBudgetUpdateStart(context map[string]interface{}) string { return Nprintf(` data "google_billing_account" "account" { billing_account = "%{billing_acct}" @@ -130,7 +138,7 @@ resource "google_billing_budget" "budget" { `, context) } -func testAccBillingBudget_billingBudgetUpdateRemoveFilterEnd(context map[string]interface{}) string { +func testAccBillingBudget_billingBudgetUpdateRemoveFilter(context map[string]interface{}) string { return Nprintf(` data "google_billing_account" "account" { billing_account = "%{billing_acct}" @@ -165,6 +173,41 @@ resource "google_billing_budget" "budget" { `, context) } +func testAccBillingBudget_billingBudgetUpdateChangeAmount(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 = "2000" + } + } + + threshold_rules { + threshold_percent = 0.5 + } + threshold_rules { + threshold_percent = 0.9 + spend_basis = "FORECASTED_SPEND" + } +} +`, context) +} + func TestBillingBudgetStateUpgradeV0(t *testing.T) { t.Parallel()