Skip to content

Commit 822a736

Browse files
wj-chenamanMahendroo
authored andcommitted
Add external catalog dataset options to google_bigquery_dataset beta (GoogleCloudPlatform#12113)
1 parent 3fac703 commit 822a736

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

mmv1/products/bigquery/Dataset.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ examples:
9393
vars:
9494
dataset_id: 'example_dataset'
9595
exclude_test: true
96+
- name: 'bigquery_dataset_external_catalog_dataset_options'
97+
primary_resource_id: 'dataset'
98+
vars:
99+
dataset_id: 'example_dataset'
100+
min_version: 'beta'
96101
- name: 'bigquery_dataset_resource_tags'
97102
primary_resource_id: 'dataset'
98103
primary_resource_name: 'fmt.Sprintf("tf_test_dataset%s", context["random_suffix"])'
@@ -401,3 +406,22 @@ properties:
401406
ID of the parent organization or project resource for this tag key. Tag value is expected
402407
to be the short name, for example "Production". See [Tag definitions](/iam/docs/tags-access-control#definitions)
403408
for more details.
409+
- name: 'externalCatalogDatasetOptions'
410+
type: NestedObject
411+
description: |
412+
Options defining open source compatible datasets living in the BigQuery catalog. Contains
413+
metadata of open source database, schema or namespace represented by the current dataset.
414+
min_version: beta
415+
properties:
416+
- name: 'parameters'
417+
type: KeyValuePairs
418+
description: |
419+
A map of key value pairs defining the parameters and properties of the open source schema.
420+
Maximum size of 2Mib.
421+
min_version: beta
422+
- name: 'defaultStorageLocationUri'
423+
type: String
424+
description: |
425+
The storage location URI for all tables in the dataset. Equivalent to hive metastore's
426+
database locationUri. Maximum length of 1024 characters.
427+
min_version: beta
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "google_bigquery_dataset" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
4+
dataset_id = "{{index $.Vars "dataset_id"}}"
5+
friendly_name = "test"
6+
description = "This is a test description"
7+
location = "US"
8+
9+
external_catalog_dataset_options {
10+
parameters = {
11+
"dataset_owner" = "test_dataset_owner"
12+
}
13+
default_storage_location_uri = "gs://test_dataset/tables"
14+
}
15+
}

mmv1/third_party/terraform/services/bigquery/resource_bigquery_dataset_test.go renamed to mmv1/third_party/terraform/services/bigquery/resource_bigquery_dataset_test.go.tmpl

+76
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,42 @@ func TestAccBigQueryDataset_bigqueryDatasetResourceTags_update(t *testing.T) {
454454
})
455455
}
456456

457+
{{- if ne $.TargetVersionName "ga" }}
458+
func TestAccBigQueryDataset_externalCatalogDatasetOptions_update(t *testing.T) {
459+
t.Parallel()
460+
461+
context := map[string]interface{}{
462+
"random_suffix": acctest.RandString(t, 10),
463+
}
464+
465+
acctest.VcrTest(t, resource.TestCase{
466+
PreCheck: func() { acctest.AccTestPreCheck(t) },
467+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
468+
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
469+
Steps: []resource.TestStep{
470+
{
471+
Config: testAccBigQueryDataset_externalCatalogDatasetOptions_basic(context),
472+
},
473+
{
474+
ResourceName: "google_bigquery_dataset.dataset",
475+
ImportState: true,
476+
ImportStateVerify: true,
477+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
478+
},
479+
{
480+
Config: testAccBigQueryDataset_externalCatalogDatasetOptions_update(context),
481+
},
482+
{
483+
ResourceName: "google_bigquery_dataset.dataset",
484+
ImportState: true,
485+
ImportStateVerify: true,
486+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
487+
},
488+
},
489+
})
490+
}
491+
492+
{{- end }}
457493
func testAccAddTable(t *testing.T, datasetID string, tableID string) resource.TestCheckFunc {
458494
// Not actually a check, but adds a table independently of terraform
459495
return func(s *terraform.State) error {
@@ -864,3 +900,43 @@ resource "google_bigquery_dataset" "dataset" {
864900
}
865901
`, context)
866902
}
903+
904+
func testAccBigQueryDataset_externalCatalogDatasetOptions_basic(context map[string]interface{}) string {
905+
return acctest.Nprintf(`
906+
resource "google_bigquery_dataset" "dataset" {
907+
provider = google-beta
908+
909+
dataset_id = "dataset%{random_suffix}"
910+
friendly_name = "test"
911+
description = "This is a test description"
912+
location = "US"
913+
914+
external_catalog_dataset_options {
915+
parameters = {
916+
"dataset_owner" = "dataset_owner"
917+
}
918+
default_storage_location_uri = "gs://test_dataset/tables"
919+
}
920+
}
921+
`, context)
922+
}
923+
924+
func testAccBigQueryDataset_externalCatalogDatasetOptions_update(context map[string]interface{}) string {
925+
return acctest.Nprintf(`
926+
resource "google_bigquery_dataset" "dataset" {
927+
provider = google-beta
928+
929+
dataset_id = "dataset%{random_suffix}"
930+
friendly_name = "test"
931+
description = "This is a test description"
932+
location = "US"
933+
934+
external_catalog_dataset_options {
935+
parameters = {
936+
"new_dataset_owner" = "new_dataset_owner"
937+
}
938+
default_storage_location_uri = "gs://new_test_dataset/new_tables"
939+
}
940+
}
941+
`, context)
942+
}

0 commit comments

Comments
 (0)