Skip to content

Commit 99850a0

Browse files
Stop sending external data configuration schema when updating google_bigquery_table (#11739) (#8234)
[upstream:a864502459b19991660ef35f570f62468ac99c3c] Signed-off-by: Modular Magician <[email protected]>
1 parent fe3a61c commit 99850a0

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

.changelog/11739.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
bigquery: fixed bug of sending both `schema` and `external_data_configuration.schema` when updating `google_bigquery_table`
3+
```

google-beta/services/bigquery/resource_bigquery_table.go

+5
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,11 @@ func resourceBigQueryTableUpdate(d *schema.ResourceData, meta interface{}) error
18971897
return err
18981898
}
18991899

1900+
if table.ExternalDataConfiguration != nil && table.ExternalDataConfiguration.Schema != nil {
1901+
log.Printf("[INFO] Removing ExternalDataConfiguration.Schema when updating BigQuery table %s", d.Id())
1902+
table.ExternalDataConfiguration.Schema = nil
1903+
}
1904+
19001905
log.Printf("[INFO] Updating BigQuery table: %s", d.Id())
19011906

19021907
project, err := tpgresource.GetProject(d, config)

google-beta/services/bigquery/resource_bigquery_table_test.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func TestAccBigQueryTable_HivePartitioning(t *testing.T) {
230230
})
231231
}
232232

233-
func TestAccBigQueryTable_HivePartitioningCustomSchema(t *testing.T) {
233+
func TestAccBigQueryTable_HivePartitioningCustomSchema_update(t *testing.T) {
234234
t.Parallel()
235235
bucketName := acctest.TestBucketName(t)
236236
resourceName := "google_bigquery_table.test"
@@ -243,13 +243,22 @@ func TestAccBigQueryTable_HivePartitioningCustomSchema(t *testing.T) {
243243
CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t),
244244
Steps: []resource.TestStep{
245245
{
246-
Config: testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID),
246+
Config: testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID, "old-label"),
247247
},
248248
{
249249
ResourceName: resourceName,
250250
ImportState: true,
251251
ImportStateVerify: true,
252-
ImportStateVerifyIgnore: []string{"external_data_configuration.0.schema", "deletion_protection"},
252+
ImportStateVerifyIgnore: []string{"external_data_configuration.0.schema", "labels", "deletion_protection"},
253+
},
254+
{
255+
Config: testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID, "new-label"),
256+
},
257+
{
258+
ResourceName: resourceName,
259+
ImportState: true,
260+
ImportStateVerify: true,
261+
ImportStateVerifyIgnore: []string{"external_data_configuration.0.schema", "labels", "deletion_protection"},
253262
},
254263
},
255264
})
@@ -2131,7 +2140,7 @@ resource "google_bigquery_table" "test" {
21312140
`, bucketName, datasetID, tableID)
21322141
}
21332142

2134-
func testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID string) string {
2143+
func testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID, tableLabel string) string {
21352144
return fmt.Sprintf(`
21362145
resource "google_storage_bucket" "test" {
21372146
name = "%s"
@@ -2154,6 +2163,10 @@ resource "google_bigquery_table" "test" {
21542163
table_id = "%s"
21552164
dataset_id = google_bigquery_dataset.test.dataset_id
21562165
2166+
labels = {
2167+
label = "%s"
2168+
}
2169+
21572170
external_data_configuration {
21582171
source_format = "NEWLINE_DELIMITED_JSON"
21592172
autodetect = false
@@ -2180,7 +2193,7 @@ EOH
21802193
}
21812194
depends_on = ["google_storage_bucket_object.test"]
21822195
}
2183-
`, bucketName, datasetID, tableID)
2196+
`, bucketName, datasetID, tableID, tableLabel)
21842197
}
21852198

21862199
func testAccBigQueryTableAvroPartitioning(bucketName, avroFilePath, datasetID, tableID string) string {

0 commit comments

Comments
 (0)