Skip to content

Commit f5ae22e

Browse files
praucSarahFrench
andauthored
pubsub: allow empty filter definition (#11556)
Co-authored-by: Sarah French <[email protected]>
1 parent 8742aeb commit f5ae22e

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

mmv1/products/pubsub/Subscription.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ properties:
388388
name: 'filter'
389389
required: false
390390
validation: !ruby/object:Provider::Terraform::Validation
391-
regex: '^.{1,256}$'
391+
regex: '^.{0,256}$'
392392
description: |
393393
The subscription only delivers the messages that match the filter.
394394
Pub/Sub automatically acknowledges the messages that don't match the filter. You can filter messages

mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go

+55
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,47 @@ func TestUnitPubsubSubscription_IgnoreMissingKeyInMap(t *testing.T) {
398398
}
399399
}
400400

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+
401442
func testAccPubsubSubscription_emptyTTL(topic, subscription string) string {
402443
return fmt.Sprintf(`
403444
resource "google_pubsub_topic" "foo" {
@@ -796,3 +837,17 @@ func testAccCheckPubsubSubscriptionCache404(t *testing.T, subName string) resour
796837
return nil
797838
}
798839
}
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

Comments
 (0)