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.
This commit is contained in:
Stefan Schmidt 2017-07-13 01:05:14 +02:00 committed by Dana Hoffman
parent 23929e80f5
commit e6e91ecbed
2 changed files with 10 additions and 2 deletions

View File

@ -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 {

View File

@ -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, ""),
),
},
},
})
}