Skip to content

Commit

Permalink
Allow unlinking of billing account. (hashicorp#138)
Browse files Browse the repository at this point in the history
* Allow unlinking of billing account. Closes hashicorp#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.
  • Loading branch information
ubschmidt2 authored and danawillow committed Jul 12, 2017
1 parent 6f271d2 commit 2d71ec5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions google/resource_google_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions google/resource_google_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""),
),
},
},
})
}
Expand Down

0 comments on commit 2d71ec5

Please sign in to comment.