From ccce2dbac0e7fd6f0cd92dd35bcef74508b4c9cf Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 20 Jul 2021 21:51:49 +0000 Subject: [PATCH] make destination_dataset_id optional (#4978) Signed-off-by: Modular Magician --- .changelog/4978.txt | 3 + .../resource_bigquery_data_transfer_config.go | 10 +-- ...urce_bigquery_data_transfer_config_test.go | 65 +++++++++++++++++++ ...igquery_data_transfer_config.html.markdown | 8 +-- 4 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 .changelog/4978.txt diff --git a/.changelog/4978.txt b/.changelog/4978.txt new file mode 100644 index 0000000000..bdf7a6a84e --- /dev/null +++ b/.changelog/4978.txt @@ -0,0 +1,3 @@ +```release-note:bug +bigquerydatatransfer: fixed a bug where `destination_dataset_id` was required, it is now optional. +``` diff --git a/google-beta/resource_bigquery_data_transfer_config.go b/google-beta/resource_bigquery_data_transfer_config.go index 3d057ed5f7..c66ab82221 100644 --- a/google-beta/resource_bigquery_data_transfer_config.go +++ b/google-beta/resource_bigquery_data_transfer_config.go @@ -65,11 +65,6 @@ func resourceBigqueryDataTransferConfig() *schema.Resource { ForceNew: true, Description: `The data source id. Cannot be changed once the transfer config is created.`, }, - "destination_dataset_id": { - Type: schema.TypeString, - Required: true, - Description: `The BigQuery target dataset id.`, - }, "display_name": { Type: schema.TypeString, Required: true, @@ -91,6 +86,11 @@ reingests data for [today-10, today-1], rather than ingesting data for just [today-1]. Only valid if the data source supports the feature. Set the value to 0 to use the default value.`, }, + "destination_dataset_id": { + Type: schema.TypeString, + Optional: true, + Description: `The BigQuery target dataset id.`, + }, "disabled": { Type: schema.TypeBool, Optional: true, diff --git a/google-beta/resource_bigquery_data_transfer_config_test.go b/google-beta/resource_bigquery_data_transfer_config_test.go index 723a743968..9eab05a99f 100644 --- a/google-beta/resource_bigquery_data_transfer_config_test.go +++ b/google-beta/resource_bigquery_data_transfer_config_test.go @@ -17,6 +17,7 @@ func TestAccBigqueryDataTransferConfig(t *testing.T) { "basic": testAccBigqueryDataTransferConfig_scheduledQuery_basic, "update": testAccBigqueryDataTransferConfig_scheduledQuery_update, "service_account": testAccBigqueryDataTransferConfig_scheduledQuery_with_service_account, + "no_destintation": testAccBigqueryDataTransferConfig_scheduledQuery_no_destination, "booleanParam": testAccBigqueryDataTransferConfig_copy_booleanParam, } @@ -89,6 +90,32 @@ func testAccBigqueryDataTransferConfig_scheduledQuery_update(t *testing.T) { }) } +func testAccBigqueryDataTransferConfig_scheduledQuery_no_destination(t *testing.T) { + // Uses time.Now + skipIfVcr(t) + random_suffix := randString(t, 10) + now := time.Now().UTC() + start_time := now.Add(1 * time.Hour).Format(time.RFC3339) + end_time := now.AddDate(0, 1, 0).Format(time.RFC3339) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBigqueryDataTransferConfigDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBigqueryDataTransferConfig_scheduledQueryNoDestination(random_suffix, "third", start_time, end_time, "y"), + }, + { + ResourceName: "google_bigquery_data_transfer_config.query_config", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"location"}, + }, + }, + }) +} + func testAccBigqueryDataTransferConfig_scheduledQuery_with_service_account(t *testing.T) { random_suffix := randString(t, 10) @@ -245,6 +272,44 @@ resource "google_bigquery_data_transfer_config" "query_config" { `, random_suffix, random_suffix, random_suffix) } +func testAccBigqueryDataTransferConfig_scheduledQueryNoDestination(random_suffix, schedule, start_time, end_time, letter string) string { + return fmt.Sprintf(` +data "google_project" "project" {} + +resource "google_project_iam_member" "permissions" { + role = "roles/iam.serviceAccountShortTermTokenMinter" + member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-bigquerydatatransfer.iam.gserviceaccount.com" +} + +resource "google_pubsub_topic" "my_topic" { + name = "tf-test-my-topic-%s" +} + +resource "google_bigquery_data_transfer_config" "query_config" { + depends_on = [google_project_iam_member.permissions] + + display_name = "my-query-%s" + location = "asia-northeast1" + data_source_id = "scheduled_query" + schedule = "%s sunday of quarter 00:00" + schedule_options { + disable_auto_scheduling = false + start_time = "%s" + end_time = "%s" + } + notification_pubsub_topic = google_pubsub_topic.my_topic.id + email_preferences { + enable_failure_email = true + } + params = { + destination_table_name_template = "my_table" + write_disposition = "WRITE_APPEND" + query = "SELECT name FROM tabl WHERE x = '%s'" + } +} +`, random_suffix, random_suffix, schedule, start_time, end_time, letter) +} + func testAccBigqueryDataTransferConfig_booleanParam(random_suffix string) string { return fmt.Sprintf(` data "google_project" "project" {} diff --git a/website/docs/r/bigquery_data_transfer_config.html.markdown b/website/docs/r/bigquery_data_transfer_config.html.markdown index d5ce3f241c..6ee7c0d935 100644 --- a/website/docs/r/bigquery_data_transfer_config.html.markdown +++ b/website/docs/r/bigquery_data_transfer_config.html.markdown @@ -81,10 +81,6 @@ The following arguments are supported: (Required) The user specified display name for the transfer config. -* `destination_dataset_id` - - (Required) - The BigQuery target dataset id. - * `data_source_id` - (Required) The data source id. Cannot be changed once the transfer config is created. @@ -97,6 +93,10 @@ The following arguments are supported: - - - +* `destination_dataset_id` - + (Optional) + The BigQuery target dataset id. + * `schedule` - (Optional) Data transfer schedule. If the data source does not support a custom