Skip to content

Commit

Permalink
fix: Match all whitespace and non-whitespace for Pub/Sub subscription…
Browse files Browse the repository at this point in the history
… filter validation (#11676) (#8161)

[upstream:1f1fc6f3190c6c9345fa91c1db305a98fac7b357]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 12, 2024
1 parent ed437d2 commit 6934add
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/11676.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pubsub: allowed `google_pubsub_subscription` `filter` field to contain line breaks
```
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Example - "3.5s".`,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateRegexp(`^.{0,256}$`),
ValidateFunc: verify.ValidateRegexp(`^[\s\S]{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
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,55 @@ resource "google_pubsub_subscription" "example" {
`, context)
}

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

context := map[string]interface{}{
"random_suffix": 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_pubsubSubscriptionPullFilterExample(context),
},
{
ResourceName: "google_pubsub_subscription.example",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "topic"},
},
},
})
}

func testAccPubsubSubscription_pubsubSubscriptionPullFilterExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_pubsub_topic" "example" {
name = "tf-test-example-topic%{random_suffix}"
}
resource "google_pubsub_subscription" "example" {
name = "tf-test-example-subscription%{random_suffix}"
topic = google_pubsub_topic.example.id
labels = {
foo = "bar"
}
filter = <<EOF
attributes.foo = "foo"
AND attributes.bar = "bar"
EOF
ack_deadline_seconds = 20
}
`, context)
}

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

Expand Down
29 changes: 29 additions & 0 deletions website/docs/r/pubsub_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ resource "google_pubsub_subscription" "example" {
enable_message_ordering = false
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jparrowsec.cn%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=pubsub_subscription_pull_filter&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Pubsub Subscription Pull Filter


```hcl
resource "google_pubsub_topic" "example" {
name = "example-topic"
}
resource "google_pubsub_subscription" "example" {
name = "example-subscription"
topic = google_pubsub_topic.example.id
labels = {
foo = "bar"
}
filter = <<EOF
attributes.foo = "foo"
AND attributes.bar = "bar"
EOF
ack_deadline_seconds = 20
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jparrowsec.cn%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=pubsub_subscription_dead_letter&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down

0 comments on commit 6934add

Please sign in to comment.