Skip to content

Add external catalog dataset options to google_bigquery_dataset beta #12113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading