@@ -250,7 +250,7 @@ func TestAccPubsubSubscriptionBigQuery_serviceAccount(t *testing.T) {
250
250
})
251
251
}
252
252
253
- func TestAccPubsubSubscriptionCloudStorage_update (t * testing.T ) {
253
+ func TestAccPubsubSubscriptionCloudStorage_updateText (t * testing.T ) {
254
254
t .Parallel ()
255
255
256
256
bucket := fmt .Sprintf ("tf-test-bucket-%s" , acctest .RandString (t , 10 ))
@@ -263,7 +263,7 @@ func TestAccPubsubSubscriptionCloudStorage_update(t *testing.T) {
263
263
CheckDestroy : testAccCheckPubsubSubscriptionDestroyProducer (t ),
264
264
Steps : []resource.TestStep {
265
265
{
266
- Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "" , "" , "" , 0 , "" , " " ),
266
+ Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "" , "" , "" , 0 , "" , 0 , "" , "text " ),
267
267
},
268
268
{
269
269
ResourceName : "google_pubsub_subscription.foo" ,
@@ -272,7 +272,41 @@ func TestAccPubsubSubscriptionCloudStorage_update(t *testing.T) {
272
272
ImportStateVerify : true ,
273
273
},
274
274
{
275
- Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "pre-" , "-suffix" , "YYYY-MM-DD/hh_mm_ssZ" , 1000 , "300s" , "" ),
275
+ Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "pre-" , "-suffix" , "YYYY-MM-DD/hh_mm_ssZ" , 1000 , "300s" , 1000 , "" , "text" ),
276
+ },
277
+ {
278
+ ResourceName : "google_pubsub_subscription.foo" ,
279
+ ImportStateId : subscriptionShort ,
280
+ ImportState : true ,
281
+ ImportStateVerify : true ,
282
+ },
283
+ },
284
+ })
285
+ }
286
+
287
+ func TestAccPubsubSubscriptionCloudStorage_updateAvro (t * testing.T ) {
288
+ t .Parallel ()
289
+
290
+ bucket := fmt .Sprintf ("tf-test-bucket-%s" , acctest .RandString (t , 10 ))
291
+ topic := fmt .Sprintf ("tf-test-topic-%s" , acctest .RandString (t , 10 ))
292
+ subscriptionShort := fmt .Sprintf ("tf-test-sub-%s" , acctest .RandString (t , 10 ))
293
+
294
+ acctest .VcrTest (t , resource.TestCase {
295
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
296
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
297
+ CheckDestroy : testAccCheckPubsubSubscriptionDestroyProducer (t ),
298
+ Steps : []resource.TestStep {
299
+ {
300
+ Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "" , "" , "" , 0 , "" , 0 , "" , "avro" ),
301
+ },
302
+ {
303
+ ResourceName : "google_pubsub_subscription.foo" ,
304
+ ImportStateId : subscriptionShort ,
305
+ ImportState : true ,
306
+ ImportStateVerify : true ,
307
+ },
308
+ {
309
+ Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "pre-" , "-suffix" , "YYYY-MM-DD/hh_mm_ssZ" , 1000 , "300s" , 1000 , "" , "avro" ),
276
310
},
277
311
{
278
312
ResourceName : "google_pubsub_subscription.foo" ,
@@ -297,7 +331,7 @@ func TestAccPubsubSubscriptionCloudStorage_serviceAccount(t *testing.T) {
297
331
CheckDestroy : testAccCheckPubsubSubscriptionDestroyProducer (t ),
298
332
Steps : []resource.TestStep {
299
333
{
300
- Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "" , "" , "" , 0 , "" , "gcs-test-sa" ),
334
+ Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "" , "" , "" , 0 , "" , 0 , "gcs-test-sa" , "text " ),
301
335
},
302
336
{
303
337
ResourceName : "google_pubsub_subscription.foo" ,
@@ -306,7 +340,7 @@ func TestAccPubsubSubscriptionCloudStorage_serviceAccount(t *testing.T) {
306
340
ImportStateVerify : true ,
307
341
},
308
342
{
309
- Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "pre-" , "-suffix" , "YYYY-MM-DD/hh_mm_ssZ" , 1000 , "300s" , " " ),
343
+ Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "pre-" , "-suffix" , "YYYY-MM-DD/hh_mm_ssZ" , 1000 , "300s" , 1000 , "" , "text " ),
310
344
},
311
345
{
312
346
ResourceName : "google_pubsub_subscription.foo" ,
@@ -315,7 +349,7 @@ func TestAccPubsubSubscriptionCloudStorage_serviceAccount(t *testing.T) {
315
349
ImportStateVerify : true ,
316
350
},
317
351
{
318
- Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "" , "" , "" , 0 , "" , "gcs-test-sa2" ),
352
+ Config : testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscriptionShort , "" , "" , "" , 0 , "" , 0 , "gcs-test-sa2" , "avro " ),
319
353
},
320
354
{
321
355
ResourceName : "google_pubsub_subscription.foo" ,
@@ -597,10 +631,10 @@ resource "google_pubsub_subscription" "foo" {
597
631
}
598
632
599
633
func testAccPubsubSubscriptionBigQuery_basic (dataset , table , topic , subscription string , useTableSchema bool , serviceAccountId string ) string {
600
- serivceAccountEmailField := ""
601
- serivceAccountResource := ""
634
+ serviceAccountEmailField := ""
635
+ serviceAccountResource := ""
602
636
if serviceAccountId != "" {
603
- serivceAccountResource = fmt .Sprintf (`
637
+ serviceAccountResource = fmt .Sprintf (`
604
638
resource "google_service_account" "bq_write_service_account" {
605
639
account_id = "%s"
606
640
display_name = "BQ Write Service Account"
@@ -617,9 +651,9 @@ resource "google_project_iam_member" "editor" {
617
651
role = "roles/bigquery.dataEditor"
618
652
member = "serviceAccount:${google_service_account.bq_write_service_account.email}"
619
653
}` , serviceAccountId )
620
- serivceAccountEmailField = "service_account_email = google_service_account.bq_write_service_account.email"
654
+ serviceAccountEmailField = "service_account_email = google_service_account.bq_write_service_account.email"
621
655
} else {
622
- serivceAccountResource = fmt .Sprintf (`
656
+ serviceAccountResource = fmt .Sprintf (`
623
657
resource "google_project_iam_member" "viewer" {
624
658
project = data.google_project.project.project_id
625
659
role = "roles/bigquery.metadataViewer"
@@ -679,10 +713,10 @@ resource "google_pubsub_subscription" "foo" {
679
713
google_project_iam_member.editor
680
714
]
681
715
}
682
- ` , serivceAccountResource , dataset , table , topic , subscription , useTableSchema , serivceAccountEmailField )
716
+ ` , serviceAccountResource , dataset , table , topic , subscription , useTableSchema , serviceAccountEmailField )
683
717
}
684
718
685
- func testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscription , filenamePrefix , filenameSuffix , filenameDatetimeFormat string , maxBytes int , maxDuration string , serviceAccountId string ) string {
719
+ func testAccPubsubSubscriptionCloudStorage_basic (bucket , topic , subscription , filenamePrefix , filenameSuffix , filenameDatetimeFormat string , maxBytes int , maxDuration string , maxMessages int , serviceAccountId , outputFormat string ) string {
686
720
filenamePrefixString := ""
687
721
if filenamePrefix != "" {
688
722
filenamePrefixString = fmt .Sprintf (`filename_prefix = "%s"` , filenamePrefix )
@@ -703,11 +737,15 @@ func testAccPubsubSubscriptionCloudStorage_basic(bucket, topic, subscription, fi
703
737
if maxDuration != "" {
704
738
maxDurationString = fmt .Sprintf (`max_duration = "%s"` , maxDuration )
705
739
}
740
+ maxMessagesString := ""
741
+ if maxMessages != 0 {
742
+ maxMessagesString = fmt .Sprintf (`max_messages = %d` , maxMessages )
743
+ }
706
744
707
- serivceAccountEmailField := ""
708
- serivceAccountResource := ""
745
+ serviceAccountEmailField := ""
746
+ serviceAccountResource := ""
709
747
if serviceAccountId != "" {
710
- serivceAccountResource = fmt .Sprintf (`
748
+ serviceAccountResource = fmt .Sprintf (`
711
749
resource "google_service_account" "storage_write_service_account" {
712
750
account_id = "%s"
713
751
display_name = "Write Service Account"
@@ -724,14 +762,23 @@ resource "google_project_iam_member" "editor" {
724
762
role = "roles/bigquery.dataEditor"
725
763
member = "serviceAccount:${google_service_account.storage_write_service_account.email}"
726
764
}` , serviceAccountId )
727
- serivceAccountEmailField = "service_account_email = google_service_account.storage_write_service_account.email"
765
+ serviceAccountEmailField = "service_account_email = google_service_account.storage_write_service_account.email"
728
766
} else {
729
- serivceAccountResource = fmt .Sprintf (`
767
+ serviceAccountResource = fmt .Sprintf (`
730
768
resource "google_storage_bucket_iam_member" "admin" {
731
769
bucket = google_storage_bucket.test.name
732
770
role = "roles/storage.admin"
733
771
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
734
772
}` )
773
+ }
774
+ outputFormatString := ""
775
+ if outputFormat == "avro" {
776
+ outputFormatString = `
777
+ avro_config {
778
+ write_metadata = true
779
+ use_topic_schema = true
780
+ }
781
+ `
735
782
}
736
783
return fmt .Sprintf (`
737
784
data "google_project" "project" { }
@@ -758,15 +805,17 @@ resource "google_pubsub_subscription" "foo" {
758
805
%s
759
806
%s
760
807
%s
761
- %s
808
+ %s
809
+ %s
810
+ %s
762
811
}
763
812
764
813
depends_on = [
765
814
google_storage_bucket.test,
766
815
google_storage_bucket_iam_member.admin,
767
816
]
768
817
}
769
- ` , bucket , serivceAccountResource , topic , subscription , filenamePrefixString , filenameSuffixString , filenameDatetimeString , maxBytesString , maxDurationString , serivceAccountEmailField )
818
+ ` , bucket , serviceAccountResource , topic , subscription , filenamePrefixString , filenameSuffixString , filenameDatetimeString , maxBytesString , maxDurationString , maxMessagesString , serviceAccountEmailField , outputFormatString )
770
819
}
771
820
772
821
func testAccPubsubSubscription_topicOnly (topic string ) string {
0 commit comments