Skip to content

Commit

Permalink
Stop sending external data configuration schema when updating google_…
Browse files Browse the repository at this point in the history
…bigquery_table (GoogleCloudPlatform#11739)
  • Loading branch information
wj-chen authored and Philip Jonany committed Nov 4, 2024
1 parent 5778b8d commit 242827e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,11 @@ func resourceBigQueryTableUpdate(d *schema.ResourceData, meta interface{}) error
return err
}

if table.ExternalDataConfiguration != nil && table.ExternalDataConfiguration.Schema != nil {
log.Printf("[INFO] Removing ExternalDataConfiguration.Schema when updating BigQuery table %s", d.Id())
table.ExternalDataConfiguration.Schema = nil
}

log.Printf("[INFO] Updating BigQuery table: %s", d.Id())

project, err := tpgresource.GetProject(d, config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestAccBigQueryTable_HivePartitioning(t *testing.T) {
})
}

func TestAccBigQueryTable_HivePartitioningCustomSchema(t *testing.T) {
func TestAccBigQueryTable_HivePartitioningCustomSchema_update(t *testing.T) {
t.Parallel()
bucketName := acctest.TestBucketName(t)
resourceName := "google_bigquery_table.test"
Expand All @@ -241,13 +241,22 @@ func TestAccBigQueryTable_HivePartitioningCustomSchema(t *testing.T) {
CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID),
Config: testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID, "old-label"),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"external_data_configuration.0.schema", "deletion_protection"},
ImportStateVerifyIgnore: []string{"external_data_configuration.0.schema", "labels", "deletion_protection"},
},
{
Config: testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID, "new-label"),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"external_data_configuration.0.schema", "labels", "deletion_protection"},
},
},
})
Expand Down Expand Up @@ -2129,7 +2138,7 @@ resource "google_bigquery_table" "test" {
`, bucketName, datasetID, tableID)
}

func testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID string) string {
func testAccBigQueryTableHivePartitioningCustomSchema(bucketName, datasetID, tableID, tableLabel string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "test" {
name = "%s"
Expand All @@ -2152,6 +2161,10 @@ resource "google_bigquery_table" "test" {
table_id = "%s"
dataset_id = google_bigquery_dataset.test.dataset_id
labels = {
label = "%s"
}
external_data_configuration {
source_format = "NEWLINE_DELIMITED_JSON"
autodetect = false
Expand All @@ -2178,7 +2191,7 @@ EOH
}
depends_on = ["google_storage_bucket_object.test"]
}
`, bucketName, datasetID, tableID)
`, bucketName, datasetID, tableID, tableLabel)
}

func testAccBigQueryTableAvroPartitioning(bucketName, avroFilePath, datasetID, tableID string) string {
Expand Down

0 comments on commit 242827e

Please sign in to comment.