Skip to content

Commit aa28c78

Browse files
committed
impl(google_bigquery_table): exposing 'TableMetadataView' query param as 'table_metadata_view'
1 parent fed2c98 commit aa28c78

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

mmv1/products/bigquery/Table.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,11 @@ properties:
645645
from BigQuery Engine. The connection_id can have the form `<project_id>.<location_id>.<connection_id>`
646646
or `projects/<project_id>/locations/<location_id>/connections/<connection_id>`.
647647
min_version: beta
648+
virtual_fields:
649+
- name: 'table_metadata_view'
650+
type: String
651+
description: |
652+
View sets the optional parameter "view": Specifies the view that determines which table information is
653+
returned. By default, basic table information and storage statistics (STORAGE_STATS) are returned.
654+
Possible values: TABLE_METADATA_VIEW_UNSPECIFIED, BASIC, STORAGE_STATS, FULL
655+
default_value: "TABLE_METADATA_VIEW_UNSPECIFIED"

mmv1/third_party/terraform/services/bigquery/resource_bigquery_table.go.tmpl

+14-1
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,12 @@ func ResourceBigQueryTable() *schema.Resource {
14471447
},
14481448
},
14491449
},
1450+
"table_metadata_view": {
1451+
Type: schema.TypeString,
1452+
Optional: true,
1453+
Default: "TABLE_METADATA_VIEW_UNSPECIFIED",
1454+
Description: `View sets the optional parameter "view": Specifies the view that determines which table information is returned. By default, basic table information and storage statistics (STORAGE_STATS) are returned. Possible values: TABLE_METADATA_VIEW_UNSPECIFIED, BASIC, STORAGE_STATS, FULL`,
1455+
},
14501456
// TableReplicationInfo: [Optional] Replication info of a table created using `AS REPLICA` DDL like: `CREATE MATERIALIZED VIEW mv1 AS REPLICA OF src_mv`.
14511457
"table_replication_info": {
14521458
Type: schema.TypeList,
@@ -1834,7 +1840,14 @@ func resourceBigQueryTableRead(d *schema.ResourceData, meta interface{}) error {
18341840
datasetID := d.Get("dataset_id").(string)
18351841
tableID := d.Get("table_id").(string)
18361842

1837-
res, err := config.NewBigQueryClient(userAgent).Tables.Get(project, datasetID, tableID).Do()
1843+
tableMetadataView := d.Get("table_metadata_view").(string)
1844+
1845+
client := config.NewBigQueryClient(userAgent).Tables.Get(project, datasetID, tableID)
1846+
if len(tableMetadataView) > 0 {
1847+
client = client.View(tableMetadataView)
1848+
}
1849+
res, err := client.Do()
1850+
18381851
if err != nil {
18391852
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("BigQuery table %q", tableID))
18401853
}

mmv1/third_party/terraform/services/bigquery/resource_bigquery_table_test.go.tmpl

+51-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestAccBigQueryTable_Basic(t *testing.T) {
3030
ResourceName: "google_bigquery_table.test",
3131
ImportState: true,
3232
ImportStateVerify: true,
33-
ImportStateVerifyIgnore: []string{"deletion_protection"},
33+
ImportStateVerifyIgnore: []string{"deletion_protection", "last_modified_time"},
3434
},
3535
{
3636
Config: testAccBigQueryTableUpdated(datasetID, tableID),
@@ -39,7 +39,40 @@ func TestAccBigQueryTable_Basic(t *testing.T) {
3939
ResourceName: "google_bigquery_table.test",
4040
ImportState: true,
4141
ImportStateVerify: true,
42-
ImportStateVerifyIgnore: []string{"deletion_protection"},
42+
ImportStateVerifyIgnore: []string{"deletion_protection", "last_modified_time"},
43+
},
44+
},
45+
})
46+
}
47+
48+
func TestAccBigQueryTable_TableMetadataView(t *testing.T) {
49+
t.Parallel()
50+
51+
datasetID := fmt.Sprintf("tf_test_%s", acctest.RandString(t, 10))
52+
tableID := fmt.Sprintf("tf_test_%s", acctest.RandString(t, 10))
53+
54+
acctest.VcrTest(t, resource.TestCase{
55+
PreCheck: func() { acctest.AccTestPreCheck(t) },
56+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
57+
CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t),
58+
Steps: []resource.TestStep{
59+
{
60+
Config: testAccBigQueryTableBasicWithTableMetadataView(datasetID, tableID),
61+
},
62+
{
63+
ResourceName: "google_bigquery_table.test",
64+
ImportState: true,
65+
ImportStateVerify: true,
66+
ImportStateVerifyIgnore: []string{"deletion_protection", "table_metadata_view"},
67+
},
68+
{
69+
Config: testAccBigQueryTableUpdated(datasetID, tableID),
70+
},
71+
{
72+
ResourceName: "google_bigquery_table.test",
73+
ImportState: true,
74+
ImportStateVerify: true,
75+
ImportStateVerifyIgnore: []string{"deletion_protection", "table_metadata_view"},
4376
},
4477
},
4578
})
@@ -1950,6 +1983,22 @@ EOH
19501983
`, datasetID, tableID)
19511984
}
19521985

1986+
func testAccBigQueryTableBasicWithTableMetadataView(datasetID, tableID string) string {
1987+
return fmt.Sprintf(`
1988+
resource "google_bigquery_dataset" "test" {
1989+
dataset_id = "%s"
1990+
}
1991+
1992+
resource "google_bigquery_table" "test" {
1993+
deletion_protection = false
1994+
table_id = "%s"
1995+
dataset_id = google_bigquery_dataset.test.dataset_id
1996+
1997+
table_metadata_view = "BASIC"
1998+
}
1999+
`, datasetID, tableID)
2000+
}
2001+
19532002
func testAccBigQueryTableBasicSchemaWithDeletionProtection(datasetID, tableID string) string {
19542003
return fmt.Sprintf(`
19552004
resource "google_bigquery_dataset" "test" {

0 commit comments

Comments
 (0)