From 0bcaffb1fd6b4902df87078a96693d9acbc7a0d1 Mon Sep 17 00:00:00 2001 From: Drew Boshardy Date: Mon, 3 Aug 2020 11:17:08 -0500 Subject: [PATCH 1/5] implement check for errors in polling for job create --- google/resource_big_query_job.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/google/resource_big_query_job.go b/google/resource_big_query_job.go index b46b4eb8344..037d5487fe0 100644 --- a/google/resource_big_query_job.go +++ b/google/resource_big_query_job.go @@ -15,6 +15,7 @@ package google import ( + "errors" "fmt" "log" "reflect" @@ -910,6 +911,16 @@ func resourceBigQueryJobCreate(d *schema.ResourceData, meta interface{}) error { return resourceBigQueryJobRead(d, meta) } +func resourceBigQueryJobCheckCreateResponseForError(res map[string]interface{}) (map[string]interface{}, error) { + status := res["status"].(map[string]interface{}) + errorResult := status["errorResult"].(map[string]interface{}) + if errorResult != nil { + message := errorResult["message"].(string) + return res, errors.New(message) + } + return res, nil +} + func resourceBigQueryJobPollRead(d *schema.ResourceData, meta interface{}) PollReadFunc { return func() (map[string]interface{}, error) { config := meta.(*Config) @@ -927,6 +938,10 @@ func resourceBigQueryJobPollRead(d *schema.ResourceData, meta interface{}) PollR if err != nil { return res, err } + res, err = resourceBigQueryJobCheckCreateResponseForError(res) + if err != nil { + return res, err + } return res, nil } } From 117bff42ffd8b05c69ea193642da7bc9ddc46b8e Mon Sep 17 00:00:00 2001 From: Drew Boshardy Date: Mon, 3 Aug 2020 11:17:42 -0500 Subject: [PATCH 2/5] remove check that prevents useLegacySql from being honored in request --- google/resource_big_query_job.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/resource_big_query_job.go b/google/resource_big_query_job.go index 037d5487fe0..b7526b4de6b 100644 --- a/google/resource_big_query_job.go +++ b/google/resource_big_query_job.go @@ -1879,7 +1879,7 @@ func expandBigQueryJobConfigurationQuery(v interface{}, d TerraformResourceData, transformedUseLegacySql, err := expandBigQueryJobConfigurationQueryUseLegacySql(original["use_legacy_sql"], d, config) if err != nil { return nil, err - } else if val := reflect.ValueOf(transformedUseLegacySql); val.IsValid() && !isEmptyValue(val) { + } else if val := reflect.ValueOf(transformedUseLegacySql); val.IsValid() { transformed["useLegacySql"] = transformedUseLegacySql } From 680480711182c2bd9a18ea391c723324fd9226b8 Mon Sep 17 00:00:00 2001 From: Drew Boshardy Date: Mon, 3 Aug 2020 12:39:52 -0500 Subject: [PATCH 3/5] remove check for error --- google/resource_big_query_job.go | 21 +++++---------------- version/version.go | 2 +- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/google/resource_big_query_job.go b/google/resource_big_query_job.go index b7526b4de6b..c723865ec5f 100644 --- a/google/resource_big_query_job.go +++ b/google/resource_big_query_job.go @@ -15,7 +15,6 @@ package google import ( - "errors" "fmt" "log" "reflect" @@ -911,16 +910,6 @@ func resourceBigQueryJobCreate(d *schema.ResourceData, meta interface{}) error { return resourceBigQueryJobRead(d, meta) } -func resourceBigQueryJobCheckCreateResponseForError(res map[string]interface{}) (map[string]interface{}, error) { - status := res["status"].(map[string]interface{}) - errorResult := status["errorResult"].(map[string]interface{}) - if errorResult != nil { - message := errorResult["message"].(string) - return res, errors.New(message) - } - return res, nil -} - func resourceBigQueryJobPollRead(d *schema.ResourceData, meta interface{}) PollReadFunc { return func() (map[string]interface{}, error) { config := meta.(*Config) @@ -938,10 +927,6 @@ func resourceBigQueryJobPollRead(d *schema.ResourceData, meta interface{}) PollR if err != nil { return res, err } - res, err = resourceBigQueryJobCheckCreateResponseForError(res) - if err != nil { - return res, err - } return res, nil } } @@ -1816,7 +1801,7 @@ func expandBigQueryJobConfigurationQuery(v interface{}, d TerraformResourceData, transformedCreateDisposition, err := expandBigQueryJobConfigurationQueryCreateDisposition(original["create_disposition"], d, config) if err != nil { return nil, err - } else if val := reflect.ValueOf(transformedCreateDisposition); val.IsValid() && !isEmptyValue(val) { + } else if val := reflect.ValueOf(transformedCreateDisposition); val.IsValid() && !isEmptyValue(val) && !queryContainsDML(transformedQuery, d, config){ transformed["createDisposition"] = transformedCreateDisposition } @@ -1914,6 +1899,10 @@ func expandBigQueryJobConfigurationQuery(v interface{}, d TerraformResourceData, return transformed, nil } +func queryContainsDML(query interface{}, d TerraformResourceData, config *Config) bool { + +} + func expandBigQueryJobConfigurationQueryQuery(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/version/version.go b/version/version.go index b2d946a5d20..b85c4fb4344 100644 --- a/version/version.go +++ b/version/version.go @@ -2,5 +2,5 @@ package version var ( // ProviderVersion is set during the release process to the release version of the binary - ProviderVersion = "dev" + ProviderVersion = "4.11" ) From c67c6c598b980d708c7263cc4dfe2e5bf568aa20 Mon Sep 17 00:00:00 2001 From: Drew Boshardy Date: Mon, 3 Aug 2020 13:07:56 -0500 Subject: [PATCH 4/5] add docs warning for DML language statements --- google/resource_big_query_job.go | 6 +----- website/docs/r/bigquery_job.html.markdown | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/google/resource_big_query_job.go b/google/resource_big_query_job.go index c723865ec5f..5fb71151cce 100644 --- a/google/resource_big_query_job.go +++ b/google/resource_big_query_job.go @@ -1801,7 +1801,7 @@ func expandBigQueryJobConfigurationQuery(v interface{}, d TerraformResourceData, transformedCreateDisposition, err := expandBigQueryJobConfigurationQueryCreateDisposition(original["create_disposition"], d, config) if err != nil { return nil, err - } else if val := reflect.ValueOf(transformedCreateDisposition); val.IsValid() && !isEmptyValue(val) && !queryContainsDML(transformedQuery, d, config){ + } else if val := reflect.ValueOf(transformedCreateDisposition); val.IsValid() && !isEmptyValue(val) { transformed["createDisposition"] = transformedCreateDisposition } @@ -1899,10 +1899,6 @@ func expandBigQueryJobConfigurationQuery(v interface{}, d TerraformResourceData, return transformed, nil } -func queryContainsDML(query interface{}, d TerraformResourceData, config *Config) bool { - -} - func expandBigQueryJobConfigurationQueryQuery(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/website/docs/r/bigquery_job.html.markdown b/website/docs/r/bigquery_job.html.markdown index c13a7dcf274..f6b3cd5b62d 100644 --- a/website/docs/r/bigquery_job.html.markdown +++ b/website/docs/r/bigquery_job.html.markdown @@ -381,6 +381,8 @@ The `query` block supports: * `query` - (Required) SQL query text to execute. The useLegacySql field can be used to indicate whether the query uses legacy SQL or standard SQL. + *NOTE*: queries containing [DML language](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-manipulation-language) + (`DELETE`, `UPDATE`, `MERGE`, `INSERT`) must specify `create_disposition = ""` and `write_disposition = ""`. * `destination_table` - (Optional) From 03c81a776b2aef80a903af3c95295f79cad4a333 Mon Sep 17 00:00:00 2001 From: Drew Boshardy Date: Mon, 3 Aug 2020 13:23:15 -0500 Subject: [PATCH 5/5] rollback change to version --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index b85c4fb4344..b2d946a5d20 100644 --- a/version/version.go +++ b/version/version.go @@ -2,5 +2,5 @@ package version var ( // ProviderVersion is set during the release process to the release version of the binary - ProviderVersion = "4.11" + ProviderVersion = "dev" )