From c505e81eef672be3eaff1be575ee4d2515ce198a Mon Sep 17 00:00:00 2001 From: Seth Hollyman Date: Wed, 31 Jul 2019 09:36:57 -0700 Subject: [PATCH] bigquery: add clustering --- .../resources/resource_bigquery_table.go.erb | 19 +++++++++++++++++++ .../tests/resource_bigquery_table_test.go | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/third_party/terraform/resources/resource_bigquery_table.go.erb b/third_party/terraform/resources/resource_bigquery_table.go.erb index e8f7c8cc771d..13b8b5254c84 100644 --- a/third_party/terraform/resources/resource_bigquery_table.go.erb +++ b/third_party/terraform/resources/resource_bigquery_table.go.erb @@ -303,6 +303,14 @@ func resourceBigQueryTable() *schema.Resource { }, }, + // Clustering: [Optional] Ordered set of up to 4 columns for clustering this table. + "clustering": &schema.Schema{ + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + // CreationTime: [Output-only] The time when this table was created, in // milliseconds since the epoch. "creation_time": { @@ -435,6 +443,13 @@ func resourceTable(d *schema.ResourceData, meta interface{}) (*bigquery.Table, e table.TimePartitioning = expandTimePartitioning(v) } + if v, ok := d.GetOk("clustering"); ok { + table.Clustering = &bigquery.Clustering{ + Fields: convertStringArr(v.([]interface{})), + ForceSendFields: []string{"Fields"}, + } + } + return table, nil } @@ -514,6 +529,10 @@ func resourceBigQueryTableRead(d *schema.ResourceData, meta interface{}) error { } } + if res.Clustering != nil { + d.Set("clustering", res.Clustering.Fields) + } + if res.Schema != nil { schema, err := flattenSchema(res.Schema) if err != nil { diff --git a/third_party/terraform/tests/resource_bigquery_table_test.go b/third_party/terraform/tests/resource_bigquery_table_test.go index 2aa023f0c45d..c6ed5e8f2ec9 100644 --- a/third_party/terraform/tests/resource_bigquery_table_test.go +++ b/third_party/terraform/tests/resource_bigquery_table_test.go @@ -178,13 +178,22 @@ resource "google_bigquery_table" "test" { type = "DAY" field = "ts" require_partition_filter = true - } + } + clustering = ["some_number", "some_state"] schema = <