Skip to content

Commit 0eb9f90

Browse files
modular-magicianroaks3
authored andcommitted
pubsub: allow empty filter definition (#11556) (#8055)
[upstream:f5ae22e34495c7e2d439594854198937b17107a1] Signed-off-by: Modular Magician <[email protected]>
1 parent 51bc589 commit 0eb9f90

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

.changelog/11556.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
pubsub: fixed a validation bug that didn't allow empty filter definitions for `google_pubsub_subscription` resources
3+
```

google-beta/services/pubsub/resource_pubsub_subscription.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Example - "3.5s".`,
356356
Type: schema.TypeString,
357357
Optional: true,
358358
ForceNew: true,
359-
ValidateFunc: verify.ValidateRegexp(`^.{1,256}$`),
359+
ValidateFunc: verify.ValidateRegexp(`^.{0,256}$`),
360360
Description: `The subscription only delivers the messages that match the filter.
361361
Pub/Sub automatically acknowledges the messages that don't match the filter. You can filter messages
362362
by their attributes. The maximum length of a filter is 256 bytes. After creating the subscription,

google-beta/services/pubsub/resource_pubsub_subscription_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,47 @@ func TestUnitPubsubSubscription_IgnoreMissingKeyInMap(t *testing.T) {
400400
}
401401
}
402402

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

0 commit comments

Comments
 (0)