Skip to content

Commit e4291d1

Browse files
make destination_dataset_id optional (#4978) (#3438)
Signed-off-by: Modular Magician <[email protected]>
1 parent 4e068e9 commit e4291d1

File tree

4 files changed

+77
-9
lines changed

4 files changed

+77
-9
lines changed

.changelog/4978.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
bigquerydatatransfer: fixed a bug where `destination_dataset_id` was required, it is now optional.
3+
```

google-beta/resource_bigquery_data_transfer_config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ func resourceBigqueryDataTransferConfig() *schema.Resource {
6565
ForceNew: true,
6666
Description: `The data source id. Cannot be changed once the transfer config is created.`,
6767
},
68-
"destination_dataset_id": {
69-
Type: schema.TypeString,
70-
Required: true,
71-
Description: `The BigQuery target dataset id.`,
72-
},
7368
"display_name": {
7469
Type: schema.TypeString,
7570
Required: true,
@@ -91,6 +86,11 @@ reingests data for [today-10, today-1], rather than ingesting data for
9186
just [today-1]. Only valid if the data source supports the feature.
9287
Set the value to 0 to use the default value.`,
9388
},
89+
"destination_dataset_id": {
90+
Type: schema.TypeString,
91+
Optional: true,
92+
Description: `The BigQuery target dataset id.`,
93+
},
9494
"disabled": {
9595
Type: schema.TypeBool,
9696
Optional: true,

google-beta/resource_bigquery_data_transfer_config_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestAccBigqueryDataTransferConfig(t *testing.T) {
1717
"basic": testAccBigqueryDataTransferConfig_scheduledQuery_basic,
1818
"update": testAccBigqueryDataTransferConfig_scheduledQuery_update,
1919
"service_account": testAccBigqueryDataTransferConfig_scheduledQuery_with_service_account,
20+
"no_destintation": testAccBigqueryDataTransferConfig_scheduledQuery_no_destination,
2021
"booleanParam": testAccBigqueryDataTransferConfig_copy_booleanParam,
2122
}
2223

@@ -89,6 +90,32 @@ func testAccBigqueryDataTransferConfig_scheduledQuery_update(t *testing.T) {
8990
})
9091
}
9192

93+
func testAccBigqueryDataTransferConfig_scheduledQuery_no_destination(t *testing.T) {
94+
// Uses time.Now
95+
skipIfVcr(t)
96+
random_suffix := randString(t, 10)
97+
now := time.Now().UTC()
98+
start_time := now.Add(1 * time.Hour).Format(time.RFC3339)
99+
end_time := now.AddDate(0, 1, 0).Format(time.RFC3339)
100+
101+
vcrTest(t, resource.TestCase{
102+
PreCheck: func() { testAccPreCheck(t) },
103+
Providers: testAccProviders,
104+
CheckDestroy: testAccCheckBigqueryDataTransferConfigDestroyProducer(t),
105+
Steps: []resource.TestStep{
106+
{
107+
Config: testAccBigqueryDataTransferConfig_scheduledQueryNoDestination(random_suffix, "third", start_time, end_time, "y"),
108+
},
109+
{
110+
ResourceName: "google_bigquery_data_transfer_config.query_config",
111+
ImportState: true,
112+
ImportStateVerify: true,
113+
ImportStateVerifyIgnore: []string{"location"},
114+
},
115+
},
116+
})
117+
}
118+
92119
func testAccBigqueryDataTransferConfig_scheduledQuery_with_service_account(t *testing.T) {
93120
random_suffix := randString(t, 10)
94121

@@ -245,6 +272,44 @@ resource "google_bigquery_data_transfer_config" "query_config" {
245272
`, random_suffix, random_suffix, random_suffix)
246273
}
247274

275+
func testAccBigqueryDataTransferConfig_scheduledQueryNoDestination(random_suffix, schedule, start_time, end_time, letter string) string {
276+
return fmt.Sprintf(`
277+
data "google_project" "project" {}
278+
279+
resource "google_project_iam_member" "permissions" {
280+
role = "roles/iam.serviceAccountShortTermTokenMinter"
281+
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-bigquerydatatransfer.iam.gserviceaccount.com"
282+
}
283+
284+
resource "google_pubsub_topic" "my_topic" {
285+
name = "tf-test-my-topic-%s"
286+
}
287+
288+
resource "google_bigquery_data_transfer_config" "query_config" {
289+
depends_on = [google_project_iam_member.permissions]
290+
291+
display_name = "my-query-%s"
292+
location = "asia-northeast1"
293+
data_source_id = "scheduled_query"
294+
schedule = "%s sunday of quarter 00:00"
295+
schedule_options {
296+
disable_auto_scheduling = false
297+
start_time = "%s"
298+
end_time = "%s"
299+
}
300+
notification_pubsub_topic = google_pubsub_topic.my_topic.id
301+
email_preferences {
302+
enable_failure_email = true
303+
}
304+
params = {
305+
destination_table_name_template = "my_table"
306+
write_disposition = "WRITE_APPEND"
307+
query = "SELECT name FROM tabl WHERE x = '%s'"
308+
}
309+
}
310+
`, random_suffix, random_suffix, schedule, start_time, end_time, letter)
311+
}
312+
248313
func testAccBigqueryDataTransferConfig_booleanParam(random_suffix string) string {
249314
return fmt.Sprintf(`
250315
data "google_project" "project" {}

website/docs/r/bigquery_data_transfer_config.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ The following arguments are supported:
8181
(Required)
8282
The user specified display name for the transfer config.
8383

84-
* `destination_dataset_id` -
85-
(Required)
86-
The BigQuery target dataset id.
87-
8884
* `data_source_id` -
8985
(Required)
9086
The data source id. Cannot be changed once the transfer config is created.
@@ -97,6 +93,10 @@ The following arguments are supported:
9793
- - -
9894

9995

96+
* `destination_dataset_id` -
97+
(Optional)
98+
The BigQuery target dataset id.
99+
100100
* `schedule` -
101101
(Optional)
102102
Data transfer schedule. If the data source does not support a custom

0 commit comments

Comments
 (0)