Skip to content

Commit

Permalink
Add external catalog dataset options to google_bigquery_dataset beta (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
wj-chen authored Oct 29, 2024
1 parent 7718828 commit eb942f6
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mmv1/products/bigquery/Dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ examples:
vars:
dataset_id: 'example_dataset'
exclude_test: true
- name: 'bigquery_dataset_external_catalog_dataset_options'
primary_resource_id: 'dataset'
vars:
dataset_id: 'example_dataset'
min_version: 'beta'
- name: 'bigquery_dataset_resource_tags'
primary_resource_id: 'dataset'
primary_resource_name: 'fmt.Sprintf("tf_test_dataset%s", context["random_suffix"])'
Expand Down Expand Up @@ -401,3 +406,22 @@ properties:
ID of the parent organization or project resource for this tag key. Tag value is expected
to be the short name, for example "Production". See [Tag definitions](/iam/docs/tags-access-control#definitions)
for more details.
- name: 'externalCatalogDatasetOptions'
type: NestedObject
description: |
Options defining open source compatible datasets living in the BigQuery catalog. Contains
metadata of open source database, schema or namespace represented by the current dataset.
min_version: beta
properties:
- name: 'parameters'
type: KeyValuePairs
description: |
A map of key value pairs defining the parameters and properties of the open source schema.
Maximum size of 2Mib.
min_version: beta
- name: 'defaultStorageLocationUri'
type: String
description: |
The storage location URI for all tables in the dataset. Equivalent to hive metastore's
database locationUri. Maximum length of 1024 characters.
min_version: beta
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "google_bigquery_dataset" "{{$.PrimaryResourceId}}" {
provider = google-beta

dataset_id = "{{index $.Vars "dataset_id"}}"
friendly_name = "test"
description = "This is a test description"
location = "US"

external_catalog_dataset_options {
parameters = {
"dataset_owner" = "test_dataset_owner"
}
default_storage_location_uri = "gs://test_dataset/tables"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,42 @@ func TestAccBigQueryDataset_bigqueryDatasetResourceTags_update(t *testing.T) {
})
}

{{- if ne $.TargetVersionName "ga" }}
func TestAccBigQueryDataset_externalCatalogDatasetOptions_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigQueryDataset_externalCatalogDatasetOptions_basic(context),
},
{
ResourceName: "google_bigquery_dataset.dataset",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
},
{
Config: testAccBigQueryDataset_externalCatalogDatasetOptions_update(context),
},
{
ResourceName: "google_bigquery_dataset.dataset",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
},
},
})
}

{{- end }}
func testAccAddTable(t *testing.T, datasetID string, tableID string) resource.TestCheckFunc {
// Not actually a check, but adds a table independently of terraform
return func(s *terraform.State) error {
Expand Down Expand Up @@ -864,3 +900,43 @@ resource "google_bigquery_dataset" "dataset" {
}
`, context)
}

func testAccBigQueryDataset_externalCatalogDatasetOptions_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_bigquery_dataset" "dataset" {
provider = google-beta

dataset_id = "dataset%{random_suffix}"
friendly_name = "test"
description = "This is a test description"
location = "US"

external_catalog_dataset_options {
parameters = {
"dataset_owner" = "dataset_owner"
}
default_storage_location_uri = "gs://test_dataset/tables"
}
}
`, context)
}

func testAccBigQueryDataset_externalCatalogDatasetOptions_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_bigquery_dataset" "dataset" {
provider = google-beta

dataset_id = "dataset%{random_suffix}"
friendly_name = "test"
description = "This is a test description"
location = "US"

external_catalog_dataset_options {
parameters = {
"new_dataset_owner" = "new_dataset_owner"
}
default_storage_location_uri = "gs://new_test_dataset/new_tables"
}
}
`, context)
}

0 comments on commit eb942f6

Please sign in to comment.