diff --git a/third_party/terraform/resources/resource_bigquery_table.go b/third_party/terraform/resources/resource_bigquery_table.go index 1cb0b25af8f3..4ddd8c954b45 100644 --- a/third_party/terraform/resources/resource_bigquery_table.go +++ b/third_party/terraform/resources/resource_bigquery_table.go @@ -451,13 +451,13 @@ func resourceBigQueryTable() *schema.Resource { Description: `Number of milliseconds for which to keep the storage for a partition.`, }, - // Type: [Required] The supported types are DAY and HOUR, which will generate - // one partition per day or hour based on data loading time. + // Type: [Required] The supported types are DAY, HOUR, MONTH, and YEAR, which will generate + // one partition per day, hour, month, and year, respectively. "type": { Type: schema.TypeString, Required: true, - Description: `The supported types are DAY and HOUR, which will generate one partition per day or hour based on data loading time.`, - ValidateFunc: validation.StringInSlice([]string{"DAY", "HOUR"}, false), + Description: `The supported types are DAY, HOUR, MONTH, and YEAR, which will generate one partition per day, hour, month, and year, respectively.`, + ValidateFunc: validation.StringInSlice([]string{"DAY", "HOUR", "MONTH", "YEAR"}, false), }, // Field: [Optional] The field used to determine how to create a time-based diff --git a/third_party/terraform/tests/resource_bigquery_table_test.go b/third_party/terraform/tests/resource_bigquery_table_test.go index fc942d91350f..3da6eba393be 100644 --- a/third_party/terraform/tests/resource_bigquery_table_test.go +++ b/third_party/terraform/tests/resource_bigquery_table_test.go @@ -20,7 +20,7 @@ func TestAccBigQueryTable_Basic(t *testing.T) { CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccBigQueryTableDailyTimePartitioning(datasetID, tableID), + Config: testAccBigQueryTableTimePartitioning(datasetID, tableID, "DAY"), }, { ResourceName: "google_bigquery_table.test", @@ -76,7 +76,69 @@ func TestAccBigQueryTable_HourlyTimePartitioning(t *testing.T) { CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccBigQueryTableHourlyTimePartitioning(datasetID, tableID), + Config: testAccBigQueryTableTimePartitioning(datasetID, tableID, "HOUR"), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBigQueryTableUpdated(datasetID, tableID), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccBigQueryTable_MonthlyTimePartitioning(t *testing.T) { + t.Parallel() + + 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: testAccBigQueryTableTimePartitioning(datasetID, tableID, "MONTH"), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBigQueryTableUpdated(datasetID, tableID), + }, + { + ResourceName: "google_bigquery_table.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccBigQueryTable_YearlyTimePartitioning(t *testing.T) { + t.Parallel() + + 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: testAccBigQueryTableTimePartitioning(datasetID, tableID, "YEAR"), }, { ResourceName: "google_bigquery_table.test", @@ -400,7 +462,7 @@ func testAccCheckBigQueryTableDestroyProducer(t *testing.T) func(s *terraform.St } } -func testAccBigQueryTableDailyTimePartitioning(datasetID, tableID string) string { +func testAccBigQueryTableTimePartitioning(datasetID, tableID, partitioningType string) string { return fmt.Sprintf(` resource "google_bigquery_dataset" "test" { dataset_id = "%s" @@ -411,7 +473,7 @@ resource "google_bigquery_table" "test" { dataset_id = google_bigquery_dataset.test.dataset_id time_partitioning { - type = "DAY" + type = "%s" field = "ts" require_partition_filter = true } @@ -454,64 +516,7 @@ resource "google_bigquery_table" "test" { EOH } -`, datasetID, tableID) -} - -func testAccBigQueryTableHourlyTimePartitioning(datasetID, tableID string) string { - return fmt.Sprintf(` -resource "google_bigquery_dataset" "test" { - dataset_id = "%s" -} - -resource "google_bigquery_table" "test" { - table_id = "%s" - dataset_id = google_bigquery_dataset.test.dataset_id - - time_partitioning { - type = "HOUR" - field = "ts" - require_partition_filter = true - } - clustering = ["some_int", "some_string"] - schema = <