Skip to content

Commit 746941a

Browse files
committed
fix the failing TestAccBigqueryDataTransferConfig
1 parent 8f91a7c commit 746941a

File tree

1 file changed

+90
-12
lines changed

1 file changed

+90
-12
lines changed

mmv1/third_party/terraform/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_test.go

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package bigquerydatatransfer_test
22

33
import (
44
"fmt"
5-
"strings"
6-
"testing"
7-
"time"
8-
95
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
106
"github.com/hashicorp/terraform-plugin-testing/terraform"
117
"github.com/hashicorp/terraform-provider-google/google/acctest"
128
"github.com/hashicorp/terraform-provider-google/google/services/bigquerydatatransfer"
139
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
1410
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
11+
"strings"
12+
"testing"
13+
"time"
1514
)
1615

1716
func TestBigqueryDataTransferConfig_resourceBigqueryDTCParamsCustomDiffFuncForceNewWhenGoogleCloudStorage(t *testing.T) {
@@ -641,6 +640,19 @@ resource "google_pubsub_topic" "my_topic" {
641640
name = "tf-test-my-topic-%s"
642641
}
643642
643+
resource "google_bigquery_table" "my_table" {
644+
deletion_protection = false
645+
646+
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
647+
table_id = "my_table"
648+
schema = <<EOF
649+
[
650+
{ "name": "name", "type": "STRING" },
651+
{ "name": "x", "type": "INTEGER" }
652+
]
653+
EOF
654+
}
655+
644656
resource "google_bigquery_data_transfer_config" "query_config" {
645657
depends_on = [google_project_iam_member.permissions]
646658
@@ -659,7 +671,7 @@ resource "google_bigquery_data_transfer_config" "query_config" {
659671
enable_failure_email = true
660672
}
661673
params = {
662-
destination_table_name_template = "my_table"
674+
destination_table_name_template = google_bigquery_table.my_table.table_id
663675
write_disposition = "WRITE_APPEND"
664676
query = "SELECT name FROM tabl WHERE x = '%s'"
665677
}
@@ -689,6 +701,13 @@ resource "google_bigquery_dataset" "my_dataset" {
689701
location = "asia-northeast1"
690702
}
691703
704+
resource "google_bigquery_table" "my_table" {
705+
deletion_protection = false
706+
707+
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
708+
table_id = "my_table"
709+
}
710+
692711
resource "google_bigquery_data_transfer_config" "query_config" {
693712
depends_on = [google_project_iam_member.data_editor]
694713
@@ -699,7 +718,7 @@ resource "google_bigquery_data_transfer_config" "query_config" {
699718
destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
700719
service_account_name = google_service_account.bqwriter.email
701720
params = {
702-
destination_table_name_template = "my_table"
721+
destination_table_name_template = google_bigquery_table.my_table.table_id
703722
write_disposition = "WRITE_APPEND"
704723
query = "SELECT 1 AS a"
705724
}
@@ -721,6 +740,26 @@ resource "google_pubsub_topic" "my_topic" {
721740
name = "tf-test-my-topic-%s"
722741
}
723742
743+
resource "google_bigquery_dataset" "my_dataset" {
744+
dataset_id = "my_dataset%s"
745+
friendly_name = "foo"
746+
description = "bar"
747+
location = "asia-northeast1"
748+
}
749+
750+
resource "google_bigquery_table" "my_table" {
751+
deletion_protection = false
752+
753+
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
754+
table_id = "my_table"
755+
schema = <<EOF
756+
[
757+
{ "name": "name", "type": "STRING" },
758+
{ "name": "x", "type": "INTEGER" }
759+
]
760+
EOF
761+
}
762+
724763
resource "google_bigquery_data_transfer_config" "query_config" {
725764
depends_on = [google_project_iam_member.permissions]
726765
@@ -738,12 +777,12 @@ resource "google_bigquery_data_transfer_config" "query_config" {
738777
enable_failure_email = true
739778
}
740779
params = {
741-
destination_table_name_template = "my_table"
780+
destination_table_name_template = google_bigquery_table.my_table.table_id
742781
write_disposition = "WRITE_APPEND"
743782
query = "SELECT name FROM tabl WHERE x = '%s'"
744783
}
745784
}
746-
`, random_suffix, random_suffix, schedule, start_time, end_time, letter)
785+
`, random_suffix, random_suffix, random_suffix, schedule, start_time, end_time, letter)
747786
}
748787

749788
func testAccBigqueryDataTransferConfig_booleanParam(random_suffix string) string {
@@ -844,7 +883,7 @@ resource "google_bigquery_data_transfer_config" "query_config" {
844883
schedule = "first sunday of quarter 00:00"
845884
destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
846885
params = {
847-
destination_table_name_template = "my_table"
886+
destination_table_name_template = google_bigquery_table.my_table.table_id
848887
write_disposition = "WRITE_APPEND"
849888
query = "SELECT name FROM table WHERE x = 'y'"
850889
}
@@ -856,6 +895,19 @@ resource "google_bigquery_dataset" "my_dataset" {
856895
description = "bar"
857896
location = "us-central1"
858897
}
898+
899+
resource "google_bigquery_table" "my_table" {
900+
deletion_protection = false
901+
902+
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
903+
table_id = "my_table"
904+
schema = <<EOF
905+
[
906+
{ "name": "name", "type": "STRING" },
907+
{ "name": "x", "type": "INTEGER" }
908+
]
909+
EOF
910+
}
859911
`, random_suffix, random_suffix, random_suffix, random_suffix, random_suffix, random_suffix, random_suffix, random_suffix)
860912
}
861913

@@ -868,6 +920,19 @@ resource "google_bigquery_dataset" "dataset" {
868920
location = "US"
869921
}
870922
923+
resource "google_bigquery_table" "my_table" {
924+
deletion_protection = false
925+
926+
dataset_id = google_bigquery_dataset.dataset.dataset_id
927+
table_id = "the-table-%s-%s"
928+
schema = <<EOF
929+
[
930+
{ "name": "name", "type": "STRING" },
931+
{ "name": "x", "type": "INTEGER" }
932+
]
933+
EOF
934+
}
935+
871936
resource "google_bigquery_data_transfer_config" "update_config" {
872937
display_name = "tf-test-%s"
873938
data_source_id = "google_cloud_storage"
@@ -876,13 +941,13 @@ resource "google_bigquery_data_transfer_config" "update_config" {
876941
877942
params = {
878943
data_path_template = "gs://bq-bucket-%s-%s/*.json"
879-
destination_table_name_template = "the-table-%s-%s"
944+
destination_table_name_template = google_bigquery_table.my_table.table_id
880945
file_format = "JSON"
881946
max_bad_records = 0
882947
write_disposition = "APPEND"
883948
}
884949
}
885-
`, random_suffix, random_suffix, random_suffix, path, random_suffix, table)
950+
`, random_suffix, random_suffix, table, random_suffix, random_suffix, path)
886951
}
887952

888953
func testAccBigqueryDataTransferConfig_scheduledQuery_updateServiceAccount(random_suffix string, service_account string) string {
@@ -907,6 +972,19 @@ resource "google_bigquery_dataset" "my_dataset" {
907972
location = "asia-northeast1"
908973
}
909974
975+
resource "google_bigquery_table" "my_table" {
976+
deletion_protection = false
977+
978+
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
979+
table_id = "my_table"
980+
schema = <<EOF
981+
[
982+
{ "name": "name", "type": "STRING" },
983+
{ "name": "x", "type": "INTEGER" }
984+
]
985+
EOF
986+
}
987+
910988
resource "google_bigquery_data_transfer_config" "query_config" {
911989
depends_on = [google_project_iam_member.data_editor]
912990
@@ -917,7 +995,7 @@ resource "google_bigquery_data_transfer_config" "query_config" {
917995
destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
918996
service_account_name = google_service_account.bqwriter%s.email
919997
params = {
920-
destination_table_name_template = "my_table"
998+
destination_table_name_template = google_bigquery_table.my_table.table_id
921999
write_disposition = "WRITE_APPEND"
9221000
query = "SELECT 1 AS a"
9231001
}

0 commit comments

Comments
 (0)