From 66b4c49596f32d8856c44de311735c09b9cc86d1 Mon Sep 17 00:00:00 2001 From: Edward Sun <42220489+edwardmedia@users.noreply.github.com> Date: Tue, 20 Jul 2021 09:22:45 -0700 Subject: [PATCH] fixed ordering of projects (#4972) * fixed ordering of projects * add a test * update the test --- mmv1/products/billingbudget/terraform.yaml | 2 + .../tests/resource_billing_budget_test.go | 126 ++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/mmv1/products/billingbudget/terraform.yaml b/mmv1/products/billingbudget/terraform.yaml index f18776482a70..df8319324d7f 100644 --- a/mmv1/products/billingbudget/terraform.yaml +++ b/mmv1/products/billingbudget/terraform.yaml @@ -87,6 +87,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides default_from_api: true budgetFilter.labels: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true + budgetFilter.projects: !ruby/object:Overrides::Terraform::PropertyOverride + is_set: true # This is for copying files over files: !ruby/object:Provider::Config::Files diff --git a/mmv1/third_party/terraform/tests/resource_billing_budget_test.go b/mmv1/third_party/terraform/tests/resource_billing_budget_test.go index 8150216374a5..4110f4bb0f45 100644 --- a/mmv1/third_party/terraform/tests/resource_billing_budget_test.go +++ b/mmv1/third_party/terraform/tests/resource_billing_budget_test.go @@ -283,3 +283,129 @@ func TestBillingBudgetStateUpgradeV0(t *testing.T) { }) } } + +func TestAccBillingBudget_budgetFilterProjectsOrdering(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "org": getTestOrgFromEnv(t), + "billing_acct": getTestBillingAccountFromEnv(t), + "random_suffix_1": randString(t, 10), + "random_suffix_2": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBillingBudget_budgetFilterProjectsOrdering1(context), + }, + { + ResourceName: "google_billing_budget.budget", + ImportState: true, + ImportStateVerify: true, + }, + + { + Config: testAccBillingBudget_budgetFilterProjectsOrdering2(context), + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + { + ResourceName: "google_billing_budget.budget", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccBillingBudget_budgetFilterProjectsOrdering1(context map[string]interface{}) string { + return Nprintf(` + +data "google_billing_account" "account" { + billing_account = "%{billing_acct}" +} + +resource "google_project" "project1" { + project_id = "tf-test-%{random_suffix_1}" + name = "tf-test-%{random_suffix_1}" + org_id = "%{org}" + billing_account = data.google_billing_account.account.id +} + +resource "google_project" "project2" { + project_id = "tf-test-%{random_suffix_2}" + name = "tf-test-%{random_suffix_2}" + org_id = "%{org}" + billing_account = data.google_billing_account.account.id +} + +resource "google_billing_budget" "budget" { + billing_account = data.google_billing_account.account.id + display_name = "Example Billing Budget" + + budget_filter { + projects = [ + "projects/${google_project.project1.number}", + "projects/${google_project.project2.number}", + ] + } + + amount { + last_period_amount = true + } + + threshold_rules { + threshold_percent = 10.0 + } +} + +`, context) +} + +func testAccBillingBudget_budgetFilterProjectsOrdering2(context map[string]interface{}) string { + return Nprintf(` + +data "google_billing_account" "account" { + billing_account = "%{billing_acct}" +} + +resource "google_project" "project1" { + project_id = "tf-test-%{random_suffix_1}" + name = "tf-test-%{random_suffix_1}" + org_id = "%{org}" + billing_account = data.google_billing_account.account.id +} + +resource "google_project" "project2" { + project_id = "tf-test-%{random_suffix_2}" + name = "tf-test-%{random_suffix_2}" + org_id = "%{org}" + billing_account = data.google_billing_account.account.id +} + +resource "google_billing_budget" "budget" { + billing_account = data.google_billing_account.account.id + display_name = "Example Billing Budget" + + budget_filter { + projects = [ + "projects/${google_project.project2.number}", + "projects/${google_project.project1.number}", + ] + } + + amount { + last_period_amount = true + } + + threshold_rules { + threshold_percent = 10.0 + } +} + +`, context) +}