Skip to content

Commit

Permalink
fixed ordering of projects (GoogleCloudPlatform#4972)
Browse files Browse the repository at this point in the history
* fixed ordering of projects

* add a test

* update the test
  • Loading branch information
edwardmedia authored and khajduczenia committed Oct 12, 2021
1 parent eedbb36 commit 66b4c49
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mmv1/products/billingbudget/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
126 changes: 126 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 @@ -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)
}

0 comments on commit 66b4c49

Please sign in to comment.