diff --git a/google/resource_google_project.go b/google/resource_google_project.go index c5765905c9a..54b21ea114f 100644 --- a/google/resource_google_project.go +++ b/google/resource_google_project.go @@ -588,12 +588,12 @@ func forceDeleteComputeNetwork(projectId, networkName string, config *Config) er func updateProjectBillingAccount(d *schema.ResourceData, config *Config) error { pid := d.Id() name := d.Get("billing_account").(string) - ba := cloudbilling.ProjectBillingInfo{} + ba := &cloudbilling.ProjectBillingInfo{} // If we're unlinking an existing billing account, an empty request does that, not an empty-string billing account. if name != "" { ba.BillingAccountName = "billingAccounts/" + name } - _, err := config.clientBilling.Projects.UpdateBillingInfo(prefixedProject(pid), &ba).Do() + _, err := config.clientBilling.Projects.UpdateBillingInfo(prefixedProject(pid), ba).Do() if err != nil { d.Set("billing_account", "") if _err, ok := err.(*googleapi.Error); ok { @@ -602,20 +602,18 @@ func updateProjectBillingAccount(d *schema.ResourceData, config *Config) error { return fmt.Errorf("Error setting billing account %q for project %q: %v", name, prefixedProject(pid), err) } for retries := 0; retries < 3; retries++ { - err = resourceGoogleProjectRead(d, config) + ba, err = config.clientBilling.Projects.GetBillingInfo(prefixedProject(pid)).Do() if err != nil { return err } - if d.Get("billing_account").(string) == name { - break + baName := strings.TrimPrefix(ba.BillingAccountName, "billingAccounts/") + if baName == name { + return nil } - time.Sleep(3) + time.Sleep(3 * time.Second) } - if d.Get("billing_account").(string) != name { - return fmt.Errorf("Timed out waiting for billing account to return correct value. Waiting for %s, got %s.", - d.Get("billding_account").(string), name) - } - return nil + return fmt.Errorf("Timed out waiting for billing account to return correct value. Waiting for %s, got %s.", + name, strings.TrimPrefix(ba.BillingAccountName, "billingAccounts/")) } func expandAppEngineApp(d *schema.ResourceData) (*appengine.Application, error) { diff --git a/google/resource_google_project_test.go b/google/resource_google_project_test.go index 0834a248421..dad6333d8d4 100644 --- a/google/resource_google_project_test.go +++ b/google/resource_google_project_test.go @@ -215,6 +215,35 @@ func TestAccProject_appEngineBasic(t *testing.T) { }) } +func TestAccProject_appEngineBasicWithBilling(t *testing.T) { + t.Parallel() + + org := getTestOrgFromEnv(t) + pid := acctest.RandomWithPrefix("tf-test") + billingId := getTestBillingAccountFromEnv(t) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccProject_appEngineBasicWithBilling(pid, org, billingId), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("google_project.acceptance", "app_engine.0.name"), + resource.TestCheckResourceAttrSet("google_project.acceptance", "app_engine.0.url_dispatch_rule.#"), + resource.TestCheckResourceAttrSet("google_project.acceptance", "app_engine.0.code_bucket"), + resource.TestCheckResourceAttrSet("google_project.acceptance", "app_engine.0.default_hostname"), + resource.TestCheckResourceAttrSet("google_project.acceptance", "app_engine.0.default_bucket"), + ), + }, + resource.TestStep{ + ResourceName: "google_project.acceptance", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccProject_appEngineUpdate(t *testing.T) { t.Parallel() @@ -472,6 +501,23 @@ resource "google_project" "acceptance" { }`, pid, pid, org) } +func testAccProject_appEngineBasicWithBilling(pid, org, billing string) string { + return fmt.Sprintf(` +resource "google_project" "acceptance" { + project_id = "%s" + name = "%s" + org_id = "%s" + + billing_account = "%s" + + app_engine { + auth_domain = "hashicorptest.com" + location_id = "us-central" + serving_status = "SERVING" + } +}`, pid, pid, org, billing) +} + func testAccProject_appEngineUpdate(pid, org string) string { return fmt.Sprintf(` resource "google_project" "acceptance" {