From f82d0d84c199fdcbb7cd3c3045be838e671cb8b9 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 29 May 2020 11:02:27 -0700 Subject: [PATCH] Add post-create retry for big query job (#3579) (#2122) Signed-off-by: Modular Magician --- .changelog/3579.txt | 3 +++ google-beta/resource_big_query_job.go | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .changelog/3579.txt diff --git a/.changelog/3579.txt b/.changelog/3579.txt new file mode 100644 index 0000000000..ba3ab8ac3d --- /dev/null +++ b/.changelog/3579.txt @@ -0,0 +1,3 @@ +```release-note:bug +`bigquery`: Fixed an issue where `google_bigquery_job` would return "was present, but now absent" error after job creation +``` diff --git a/google-beta/resource_big_query_job.go b/google-beta/resource_big_query_job.go index 0d1faaf2b1..4ccfa1b0ec 100644 --- a/google-beta/resource_big_query_job.go +++ b/google-beta/resource_big_query_job.go @@ -900,11 +900,37 @@ func resourceBigQueryJobCreate(d *schema.ResourceData, meta interface{}) error { } d.SetId(id) + err = PollingWaitTime(resourceBigQueryJobPollRead(d, meta), PollCheckForExistence, "Creating Job", d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error waiting to create Job: %s", err) + } + log.Printf("[DEBUG] Finished creating Job %q: %#v", d.Id(), res) return resourceBigQueryJobRead(d, meta) } +func resourceBigQueryJobPollRead(d *schema.ResourceData, meta interface{}) PollReadFunc { + return func() (map[string]interface{}, error) { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/jobs/{{job_id}}") + if err != nil { + return nil, err + } + + project, err := getProject(d, config) + if err != nil { + return nil, err + } + res, err := sendRequest(config, "GET", project, url, nil) + if err != nil { + return res, err + } + return res, nil + } +} + func resourceBigQueryJobRead(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config)