Skip to content

Commit

Permalink
pubsub: allow empty filter definition (#11556) (#8055)
Browse files Browse the repository at this point in the history
[upstream:f5ae22e34495c7e2d439594854198937b17107a1]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and roaks3 committed Aug 29, 2024
1 parent 51bc589 commit 0eb9f90
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/11556.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pubsub: fixed a validation bug that didn't allow empty filter definitions for `google_pubsub_subscription` resources
```
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ Example - "3.5s".`,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateRegexp(`^.{1,256}$`),
ValidateFunc: verify.ValidateRegexp(`^.{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
by their attributes. The maximum length of a filter is 256 bytes. After creating the subscription,
Expand Down
55 changes: 55 additions & 0 deletions google-beta/services/pubsub/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,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 @@ -798,3 +839,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 0eb9f90

Please sign in to comment.