Skip to content

Commit 6934add

Browse files
fix: Match all whitespace and non-whitespace for Pub/Sub subscription filter validation (#11676) (#8161)
[upstream:1f1fc6f3190c6c9345fa91c1db305a98fac7b357] Signed-off-by: Modular Magician <[email protected]>
1 parent ed437d2 commit 6934add

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

Diff for: .changelog/11676.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
pubsub: allowed `google_pubsub_subscription` `filter` field to contain line breaks
3+
```

Diff for: google-beta/services/pubsub/resource_pubsub_subscription.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ Example - "3.5s".`,
366366
Type: schema.TypeString,
367367
Optional: true,
368368
ForceNew: true,
369-
ValidateFunc: verify.ValidateRegexp(`^.{0,256}$`),
369+
ValidateFunc: verify.ValidateRegexp(`^[\s\S]{0,256}$`),
370370
Description: `The subscription only delivers the messages that match the filter.
371371
Pub/Sub automatically acknowledges the messages that don't match the filter. You can filter messages
372372
by their attributes. The maximum length of a filter is 256 bytes. After creating the subscription,

Diff for: google-beta/services/pubsub/resource_pubsub_subscription_generated_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,55 @@ resource "google_pubsub_subscription" "example" {
139139
`, context)
140140
}
141141

142+
func TestAccPubsubSubscription_pubsubSubscriptionPullFilterExample(t *testing.T) {
143+
t.Parallel()
144+
145+
context := map[string]interface{}{
146+
"random_suffix": acctest.RandString(t, 10),
147+
}
148+
149+
acctest.VcrTest(t, resource.TestCase{
150+
PreCheck: func() { acctest.AccTestPreCheck(t) },
151+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
152+
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t),
153+
Steps: []resource.TestStep{
154+
{
155+
Config: testAccPubsubSubscription_pubsubSubscriptionPullFilterExample(context),
156+
},
157+
{
158+
ResourceName: "google_pubsub_subscription.example",
159+
ImportState: true,
160+
ImportStateVerify: true,
161+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "topic"},
162+
},
163+
},
164+
})
165+
}
166+
167+
func testAccPubsubSubscription_pubsubSubscriptionPullFilterExample(context map[string]interface{}) string {
168+
return acctest.Nprintf(`
169+
resource "google_pubsub_topic" "example" {
170+
name = "tf-test-example-topic%{random_suffix}"
171+
}
172+
173+
resource "google_pubsub_subscription" "example" {
174+
name = "tf-test-example-subscription%{random_suffix}"
175+
topic = google_pubsub_topic.example.id
176+
177+
labels = {
178+
foo = "bar"
179+
}
180+
181+
filter = <<EOF
182+
attributes.foo = "foo"
183+
AND attributes.bar = "bar"
184+
EOF
185+
186+
ack_deadline_seconds = 20
187+
}
188+
`, context)
189+
}
190+
142191
func TestAccPubsubSubscription_pubsubSubscriptionDeadLetterExample(t *testing.T) {
143192
t.Parallel()
144193

Diff for: website/docs/r/pubsub_subscription.html.markdown

+29
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,35 @@ resource "google_pubsub_subscription" "example" {
102102
enable_message_ordering = false
103103
}
104104
```
105+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
106+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%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">
107+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
108+
</a>
109+
</div>
110+
## Example Usage - Pubsub Subscription Pull Filter
111+
112+
113+
```hcl
114+
resource "google_pubsub_topic" "example" {
115+
name = "example-topic"
116+
}
117+
118+
resource "google_pubsub_subscription" "example" {
119+
name = "example-subscription"
120+
topic = google_pubsub_topic.example.id
121+
122+
labels = {
123+
foo = "bar"
124+
}
125+
126+
filter = <<EOF
127+
attributes.foo = "foo"
128+
AND attributes.bar = "bar"
129+
EOF
130+
131+
ack_deadline_seconds = 20
132+
}
133+
```
105134
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
106135
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%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">
107136
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">

0 commit comments

Comments
 (0)