Skip to content
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

make destination_dataset_id optional #9605

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
3 changes: 3 additions & 0 deletions .changelog/4978.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigquerydatatransfer: fixed a bug where `destination_dataset_id` was required, it is now optional.
```
10 changes: 5 additions & 5 deletions google/resource_bigquery_data_transfer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
65 changes: 65 additions & 0 deletions google/resource_bigquery_data_transfer_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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" {}
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/bigquery_data_transfer_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down