From 2d71ec53518c66ee9b1e4efa00d10ad99499865d Mon Sep 17 00:00:00 2001 From: Stefan Schmidt Date: Thu, 13 Jul 2017 01:05:14 +0200 Subject: [PATCH] Allow unlinking of billing account. (#138) * Allow unlinking of billing account. Closes #133 * Add acceptance test for unlinking the billing account. * Just apply the resource definition without the billing account instead of setting an empty billing account. --- google/resource_google_project.go | 5 +++-- google/resource_google_project_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/google/resource_google_project.go b/google/resource_google_project.go index 4e71d0d46bb..68ab2dc68af 100644 --- a/google/resource_google_project.go +++ b/google/resource_google_project.go @@ -200,8 +200,9 @@ func resourceGoogleProjectUpdate(d *schema.ResourceData, meta interface{}) error // Billing account has changed if ok := d.HasChange("billing_account"); ok { name := d.Get("billing_account").(string) - ba := cloudbilling.ProjectBillingInfo{ - BillingAccountName: "billingAccounts/" + name, + ba := cloudbilling.ProjectBillingInfo{} + if name != "" { + ba.BillingAccountName = "billingAccounts/" + name } _, err = config.clientBilling.Projects.UpdateBillingInfo(prefixedProject(pid), &ba).Do() if err != nil { diff --git a/google/resource_google_project_test.go b/google/resource_google_project_test.go index fea4c74655f..ccafbb8d7c9 100644 --- a/google/resource_google_project_test.go +++ b/google/resource_google_project_test.go @@ -115,6 +115,13 @@ func TestAccGoogleProject_updateBilling(t *testing.T) { testAccCheckGoogleProjectHasBillingAccount("google_project.acceptance", pid, billingId2), ), }, + // Unlink the billing account + resource.TestStep{ + Config: testAccGoogleProject_create(pid, pname, org), + Check: resource.ComposeTestCheckFunc( + testAccCheckGoogleProjectHasBillingAccount("google_project.acceptance", pid, ""), + ), + }, }, }) }