@@ -398,6 +398,47 @@ func TestUnitPubsubSubscription_IgnoreMissingKeyInMap(t *testing.T) {
398
398
}
399
399
}
400
400
401
+ func TestAccPubsubSubscription_filter (t * testing.T ) {
402
+ t .Parallel ()
403
+
404
+ topic := fmt .Sprintf ("tf-test-topic-%s" , acctest .RandString (t , 10 ))
405
+ subscriptionShort := fmt .Sprintf ("tf-test-sub-%s" , acctest .RandString (t , 10 ))
406
+
407
+ acctest .VcrTest (t , resource.TestCase {
408
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
409
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
410
+ CheckDestroy : testAccCheckPubsubSubscriptionDestroyProducer (t ),
411
+ Steps : []resource.TestStep {
412
+ {
413
+ Config : testAccPubsubSubscription_filter (topic , subscriptionShort , "attributes.foo = \\ \" bar\\ \" " ),
414
+ Check : resource .ComposeTestCheckFunc (
415
+ // Test schema
416
+ resource .TestCheckResourceAttr ("google_pubsub_subscription.foo" , "filter" , "attributes.foo = \" bar\" " ),
417
+ ),
418
+ },
419
+ {
420
+ ResourceName : "google_pubsub_subscription.foo" ,
421
+ ImportStateId : subscriptionShort ,
422
+ ImportState : true ,
423
+ ImportStateVerify : true ,
424
+ },
425
+ {
426
+ Config : testAccPubsubSubscription_filter (topic , subscriptionShort , "" ),
427
+ Check : resource .ComposeTestCheckFunc (
428
+ // Test schema
429
+ resource .TestCheckResourceAttr ("google_pubsub_subscription.foo" , "filter" , "" ),
430
+ ),
431
+ },
432
+ {
433
+ ResourceName : "google_pubsub_subscription.foo" ,
434
+ ImportStateId : subscriptionShort ,
435
+ ImportState : true ,
436
+ ImportStateVerify : true ,
437
+ },
438
+ },
439
+ })
440
+ }
441
+
401
442
func testAccPubsubSubscription_emptyTTL (topic , subscription string ) string {
402
443
return fmt .Sprintf (`
403
444
resource "google_pubsub_topic" "foo" {
@@ -796,3 +837,17 @@ func testAccCheckPubsubSubscriptionCache404(t *testing.T, subName string) resour
796
837
return nil
797
838
}
798
839
}
840
+
841
+ func testAccPubsubSubscription_filter (topic , subscription , filter string ) string {
842
+ return fmt .Sprintf (`
843
+ resource "google_pubsub_topic" "foo" {
844
+ name = "%s"
845
+ }
846
+
847
+ resource "google_pubsub_subscription" "foo" {
848
+ name = "%s"
849
+ topic = google_pubsub_topic.foo.id
850
+ filter = "%s"
851
+ }
852
+ ` , topic , subscription , filter )
853
+ }
0 commit comments