@@ -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+
92119func 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+
248313func testAccBigqueryDataTransferConfig_booleanParam (random_suffix string ) string {
249314 return fmt .Sprintf (`
250315data "google_project" "project" {}
0 commit comments