mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-28 22:16:04 +00:00
don't call full read when updating billing acct (#1795)
This commit is contained in:
parent
cacdaec642
commit
080f6fe2e1
@ -588,12 +588,12 @@ func forceDeleteComputeNetwork(projectId, networkName string, config *Config) er
|
|||||||
func updateProjectBillingAccount(d *schema.ResourceData, config *Config) error {
|
func updateProjectBillingAccount(d *schema.ResourceData, config *Config) error {
|
||||||
pid := d.Id()
|
pid := d.Id()
|
||||||
name := d.Get("billing_account").(string)
|
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 we're unlinking an existing billing account, an empty request does that, not an empty-string billing account.
|
||||||
if name != "" {
|
if name != "" {
|
||||||
ba.BillingAccountName = "billingAccounts/" + 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 {
|
if err != nil {
|
||||||
d.Set("billing_account", "")
|
d.Set("billing_account", "")
|
||||||
if _err, ok := err.(*googleapi.Error); ok {
|
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)
|
return fmt.Errorf("Error setting billing account %q for project %q: %v", name, prefixedProject(pid), err)
|
||||||
}
|
}
|
||||||
for retries := 0; retries < 3; retries++ {
|
for retries := 0; retries < 3; retries++ {
|
||||||
err = resourceGoogleProjectRead(d, config)
|
ba, err = config.clientBilling.Projects.GetBillingInfo(prefixedProject(pid)).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if d.Get("billing_account").(string) == name {
|
baName := strings.TrimPrefix(ba.BillingAccountName, "billingAccounts/")
|
||||||
break
|
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.",
|
||||||
return fmt.Errorf("Timed out waiting for billing account to return correct value. Waiting for %s, got %s.",
|
name, strings.TrimPrefix(ba.BillingAccountName, "billingAccounts/"))
|
||||||
d.Get("billding_account").(string), name)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func expandAppEngineApp(d *schema.ResourceData) (*appengine.Application, error) {
|
func expandAppEngineApp(d *schema.ResourceData) (*appengine.Application, error) {
|
||||||
|
@ -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) {
|
func TestAccProject_appEngineUpdate(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@ -472,6 +501,23 @@ resource "google_project" "acceptance" {
|
|||||||
}`, pid, pid, org)
|
}`, 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 {
|
func testAccProject_appEngineUpdate(pid, org string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_project" "acceptance" {
|
resource "google_project" "acceptance" {
|
||||||
|
Loading…
Reference in New Issue
Block a user