From e597a322ba970804525102da510e0758c2f4b7e7 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Mon, 8 Mar 2021 17:09:16 +0000 Subject: [PATCH] Mark BQ's materialized view query as ForceNew (#4543) * Mark BQ's materialized view query as ForceNew * add acctest to update BigQuery Materialized View Signed-off-by: Modular Magician --- .changelog/4543.txt | 3 +++ google-beta/resource_bigquery_table.go | 1 + google-beta/resource_bigquery_table_test.go | 17 +++++++++++++++++ .../resource_dataflow_flex_template_job_test.go | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changelog/4543.txt diff --git a/.changelog/4543.txt b/.changelog/4543.txt new file mode 100644 index 0000000000..496f4c3b87 --- /dev/null +++ b/.changelog/4543.txt @@ -0,0 +1,3 @@ +```release-note:bug +bigquery: fixed materialized view to be recreated when query changes +``` diff --git a/google-beta/resource_bigquery_table.go b/google-beta/resource_bigquery_table.go index b6a484a475..8f9d2fde0f 100644 --- a/google-beta/resource_bigquery_table.go +++ b/google-beta/resource_bigquery_table.go @@ -650,6 +650,7 @@ func resourceBigQueryTable() *schema.Resource { "query": { Type: schema.TypeString, Required: true, + ForceNew: true, Description: `A query whose result is persisted.`, }, }, diff --git a/google-beta/resource_bigquery_table_test.go b/google-beta/resource_bigquery_table_test.go index cc221ee916..3d8fdcc983 100644 --- a/google-beta/resource_bigquery_table_test.go +++ b/google-beta/resource_bigquery_table_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "regexp" + "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -306,6 +307,7 @@ func TestAccBigQueryTable_MaterializedView_DailyTimePartioning_Basic(t *testing. tableID := fmt.Sprintf("tf_test_%s", randString(t, 10)) materialized_viewID := fmt.Sprintf("tf_test_%s", randString(t, 10)) query := fmt.Sprintf("SELECT count(some_string) as count, some_int, ts FROM `%s.%s` WHERE DATE(ts) = '2019-01-01' GROUP BY some_int, ts", datasetID, tableID) + queryNew := strings.ReplaceAll(query, "2019", "2020") vcrTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -327,6 +329,21 @@ func TestAccBigQueryTable_MaterializedView_DailyTimePartioning_Basic(t *testing. ImportStateVerify: true, ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"}, }, + { + Config: testAccBigQueryTableWithMatViewDailyTimePartitioning_basic(datasetID, tableID, materialized_viewID, queryNew), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"}, + }, + { + ResourceName: "google_bigquery_table.mv_test", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"}, + }, }, }) } diff --git a/google-beta/resource_dataflow_flex_template_job_test.go b/google-beta/resource_dataflow_flex_template_job_test.go index 0d037482e0..df04d28bb0 100644 --- a/google-beta/resource_dataflow_flex_template_job_test.go +++ b/google-beta/resource_dataflow_flex_template_job_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - compute "google.golang.org/api/compute/v1" + "google.golang.org/api/compute/v1" ) func TestAccDataflowFlexTemplateJob_basic(t *testing.T) {