Skip to content

Commit

Permalink
pubsub: allow empty filter definition (#11556)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah French <15078782+SarahFrench@users.noreply.github.com>
  • Loading branch information
prauc and SarahFrench authored Aug 27, 2024
1 parent 8742aeb commit f5ae22e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mmv1/products/pubsub/Subscription.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ properties:
name: 'filter'
required: false
validation: !ruby/object:Provider::Terraform::Validation
regex: '^.{1,256}$'
regex: '^.{0,256}$'
description: |
The subscription only delivers the messages that match the filter.
Pub/Sub automatically acknowledges the messages that don't match the filter. You can filter messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,47 @@ func TestUnitPubsubSubscription_IgnoreMissingKeyInMap(t *testing.T) {
}
}

func TestAccPubsubSubscription_filter(t *testing.T) {
t.Parallel()

topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(t, 10))
subscriptionShort := fmt.Sprintf("tf-test-sub-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPubsubSubscription_filter(topic, subscriptionShort, "attributes.foo = \\\"bar\\\""),
Check: resource.ComposeTestCheckFunc(
// Test schema
resource.TestCheckResourceAttr("google_pubsub_subscription.foo", "filter", "attributes.foo = \"bar\""),
),
},
{
ResourceName: "google_pubsub_subscription.foo",
ImportStateId: subscriptionShort,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccPubsubSubscription_filter(topic, subscriptionShort, ""),
Check: resource.ComposeTestCheckFunc(
// Test schema
resource.TestCheckResourceAttr("google_pubsub_subscription.foo", "filter", ""),
),
},
{
ResourceName: "google_pubsub_subscription.foo",
ImportStateId: subscriptionShort,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccPubsubSubscription_emptyTTL(topic, subscription string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
Expand Down Expand Up @@ -796,3 +837,17 @@ func testAccCheckPubsubSubscriptionCache404(t *testing.T, subName string) resour
return nil
}
}

func testAccPubsubSubscription_filter(topic, subscription, filter string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
name = "%s"
}
resource "google_pubsub_subscription" "foo" {
name = "%s"
topic = google_pubsub_topic.foo.id
filter = "%s"
}
`, topic, subscription, filter)
}

0 comments on commit f5ae22e

Please sign in to comment.