From b3287ba63a79ef7027ab0624a14b2d818aa734b1 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 22 Sep 2022 14:25:43 -0700 Subject: [PATCH] send two false fields (#6566) (#4711) * send two false fields * updates Co-authored-by: Edward Sun Signed-off-by: Modular Magician Signed-off-by: Modular Magician Co-authored-by: Edward Sun --- .changelog/6566.txt | 3 + google-beta/resource_bigquery_table.go | 2 + google-beta/resource_bigquery_table_test.go | 77 +++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 .changelog/6566.txt diff --git a/.changelog/6566.txt b/.changelog/6566.txt new file mode 100644 index 0000000000..7f4a068b9b --- /dev/null +++ b/.changelog/6566.txt @@ -0,0 +1,3 @@ +```release-note:bug +compute: send `allow_quoted_newlines` and `allow_jagged_rows` when they are set to false on `google_bigquery_table` +``` diff --git a/google-beta/resource_bigquery_table.go b/google-beta/resource_bigquery_table.go index 7d4195f4c9..090d2d43bd 100644 --- a/google-beta/resource_bigquery_table.go +++ b/google-beta/resource_bigquery_table.go @@ -1398,10 +1398,12 @@ func expandCsvOptions(configured interface{}) *bigquery.CsvOptions { if v, ok := raw["allow_jagged_rows"]; ok { opts.AllowJaggedRows = v.(bool) + opts.ForceSendFields = append(opts.ForceSendFields, "allow_jagged_rows") } if v, ok := raw["allow_quoted_newlines"]; ok { opts.AllowQuotedNewlines = v.(bool) + opts.ForceSendFields = append(opts.ForceSendFields, "allow_quoted_newlines") } if v, ok := raw["encoding"]; ok { diff --git a/google-beta/resource_bigquery_table_test.go b/google-beta/resource_bigquery_table_test.go index 9e170085f2..f5c40b050c 100644 --- a/google-beta/resource_bigquery_table_test.go +++ b/google-beta/resource_bigquery_table_test.go @@ -916,6 +916,42 @@ func TestAccBigQueryExternalDataTable_CSV_WithSchema_UpdateToConnectionID(t *tes }) } +func TestAccBigQueryExternalDataTable_CSV_WithSchema_UpdateAllowQuotedNewlines(t *testing.T) { + t.Parallel() + + bucketName := testBucketName(t) + objectName := fmt.Sprintf("tf_test_%s.csv", randString(t, 10)) + + datasetID := fmt.Sprintf("tf_test_%s", randString(t, 10)) + tableID := fmt.Sprintf("tf_test_%s", randString(t, 10)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBigQueryTableFromGCSWithSchema(datasetID, tableID, bucketName, objectName, TEST_SIMPLE_CSV, TEST_SIMPLE_CSV_SCHEMA), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"}, + }, + { + Config: testAccBigQueryTableFromGCSWithSchema_UpdatAllowQuotedNewlines(datasetID, tableID, bucketName, objectName, TEST_SIMPLE_CSV, TEST_SIMPLE_CSV_SCHEMA), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"}, + }, + }, + }) +} + func TestAccBigQueryDataTable_bigtable(t *testing.T) { t.Parallel() @@ -2034,6 +2070,47 @@ resource "google_bigquery_table" "test" { `, datasetID, bucketName, objectName, content, tableID, schema) } +func testAccBigQueryTableFromGCSWithSchema_UpdatAllowQuotedNewlines(datasetID, tableID, bucketName, objectName, content, schema string) string { + return fmt.Sprintf(` +resource "google_bigquery_dataset" "test" { + dataset_id = "%s" +} +resource "google_storage_bucket" "test" { + name = "%s" + location = "US" + force_destroy = true +} +resource "google_storage_bucket_object" "test" { + name = "%s" + content = <