From 833c2a87818a3ddb21ed5a18bc7af9dc589bdb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Sabat=C3=A9?= Date: Tue, 21 Jul 2020 17:29:38 +0800 Subject: [PATCH 1/6] Add new field filter to pubsub. Fixes: https://github.com/terraform-providers/terraform-provider-google/issues/6727 --- products/pubsub/api.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/products/pubsub/api.yaml b/products/pubsub/api.yaml index d6c06d8341c5..3f1458450a5b 100644 --- a/products/pubsub/api.yaml +++ b/products/pubsub/api.yaml @@ -244,6 +244,15 @@ objects: If ttl is not set, the associated resource never expires. A duration in seconds with up to nine fractional digits, terminated by 's'. Example - "3.5s". + - !ruby/object:Api::Type::String + name: 'name' + required: false + 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, + you can't modify the filter. + input: true - !ruby/object:Api::Type::NestedObject name: 'deadLetterPolicy' send_empty_value: true From 2a4bc3741c44d0d7875e5e49de624c0c844bfe3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Sabat=C3=A9?= Date: Wed, 22 Jul 2020 00:23:26 +0800 Subject: [PATCH 2/6] Fixed filter name, it was improperly set. --- products/pubsub/api.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/products/pubsub/api.yaml b/products/pubsub/api.yaml index 3f1458450a5b..d3f8e202d5f3 100644 --- a/products/pubsub/api.yaml +++ b/products/pubsub/api.yaml @@ -245,7 +245,7 @@ objects: A duration in seconds with up to nine fractional digits, terminated by 's'. Example - "3.5s". - !ruby/object:Api::Type::String - name: 'name' + name: 'filter' required: false description: | The subscription only delivers the messages that match the filter. From 5265edeff1c15670b89417a6241bcbebb3558f4f Mon Sep 17 00:00:00 2001 From: Tim O'Connell Date: Wed, 22 Jul 2020 19:55:38 +0800 Subject: [PATCH 3/6] add filter key to pubsub subscription unit test --- .../tests/resource_pubsub_subscription_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/third_party/terraform/tests/resource_pubsub_subscription_test.go b/third_party/terraform/tests/resource_pubsub_subscription_test.go index 91b92000cf8b..5ffac3248714 100644 --- a/third_party/terraform/tests/resource_pubsub_subscription_test.go +++ b/third_party/terraform/tests/resource_pubsub_subscription_test.go @@ -44,7 +44,7 @@ func TestAccPubsubSubscription_basic(t *testing.T) { CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccPubsubSubscription_basic(topic, subscription, "bar", 20), + Config: testAccPubsubSubscription_basic(topic, subscription, "attributes.foo = \"bar\"", "bar", 20), }, { ResourceName: "google_pubsub_subscription.foo", @@ -69,7 +69,7 @@ func TestAccPubsubSubscription_update(t *testing.T) { CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "bar", 20), + Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "attributes.foo = \"bar\"", "bar", 20), }, { ResourceName: "google_pubsub_subscription.foo", @@ -78,7 +78,7 @@ func TestAccPubsubSubscription_update(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "baz", 30), + Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "attributes.foo = \"bar\"", "baz", 30), Check: resource.TestCheckResourceAttr( "google_pubsub_subscription.foo", "path", subscriptionLong, ), @@ -212,21 +212,22 @@ resource "google_pubsub_subscription" "foo" { `, saAccount, topicFoo, subscription) } -func testAccPubsubSubscription_basic(topic, subscription, label string, deadline int) string { +func testAccPubsubSubscription_basic(topic, subscription, filter string, label string, deadline int) string { return fmt.Sprintf(` resource "google_pubsub_topic" "foo" { name = "%s" } resource "google_pubsub_subscription" "foo" { - name = "%s" - topic = google_pubsub_topic.foo.id + name = "%s" + topic = google_pubsub_topic.foo.id + filter = "%s" labels = { foo = "%s" } ack_deadline_seconds = %d } -`, topic, subscription, label, deadline) +`, topic, subscription, filter, label, deadline) } func testAccPubsubSubscription_topicOnly(topic string) string { From c5aab758eecc4bbe608d96420bd79b01db42fa1e Mon Sep 17 00:00:00 2001 From: Tim O'Connell Date: Tue, 4 Aug 2020 17:34:32 +0800 Subject: [PATCH 4/6] spaces not tabs! --- .../terraform/tests/resource_pubsub_subscription_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/terraform/tests/resource_pubsub_subscription_test.go b/third_party/terraform/tests/resource_pubsub_subscription_test.go index 5ffac3248714..c621674cf48d 100644 --- a/third_party/terraform/tests/resource_pubsub_subscription_test.go +++ b/third_party/terraform/tests/resource_pubsub_subscription_test.go @@ -220,8 +220,8 @@ resource "google_pubsub_topic" "foo" { resource "google_pubsub_subscription" "foo" { name = "%s" - topic = google_pubsub_topic.foo.id - filter = "%s" + topic = google_pubsub_topic.foo.id + filter = "%s" labels = { foo = "%s" } From 8bb10e6e9dc9faacb97380570698d160e1a3c5d9 Mon Sep 17 00:00:00 2001 From: Tim O'Connell Date: Tue, 11 Aug 2020 23:53:06 +0800 Subject: [PATCH 5/6] hardcode filter value in test --- .../tests/resource_pubsub_subscription_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/third_party/terraform/tests/resource_pubsub_subscription_test.go b/third_party/terraform/tests/resource_pubsub_subscription_test.go index c621674cf48d..c8084b50cfcf 100644 --- a/third_party/terraform/tests/resource_pubsub_subscription_test.go +++ b/third_party/terraform/tests/resource_pubsub_subscription_test.go @@ -44,7 +44,7 @@ func TestAccPubsubSubscription_basic(t *testing.T) { CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccPubsubSubscription_basic(topic, subscription, "attributes.foo = \"bar\"", "bar", 20), + Config: testAccPubsubSubscription_basic(topic, subscription, "bar", 20), }, { ResourceName: "google_pubsub_subscription.foo", @@ -69,7 +69,7 @@ func TestAccPubsubSubscription_update(t *testing.T) { CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "attributes.foo = \"bar\"", "bar", 20), + Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "bar", 20), }, { ResourceName: "google_pubsub_subscription.foo", @@ -78,7 +78,7 @@ func TestAccPubsubSubscription_update(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "attributes.foo = \"bar\"", "baz", 30), + Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "baz", 30), Check: resource.TestCheckResourceAttr( "google_pubsub_subscription.foo", "path", subscriptionLong, ), @@ -212,7 +212,7 @@ resource "google_pubsub_subscription" "foo" { `, saAccount, topicFoo, subscription) } -func testAccPubsubSubscription_basic(topic, subscription, filter string, label string, deadline int) string { +func testAccPubsubSubscription_basic(topic, subscription, label string, deadline int) string { return fmt.Sprintf(` resource "google_pubsub_topic" "foo" { name = "%s" @@ -221,13 +221,13 @@ resource "google_pubsub_topic" "foo" { resource "google_pubsub_subscription" "foo" { name = "%s" topic = google_pubsub_topic.foo.id - filter = "%s" + filter = "attributes.foo = "bar"" labels = { foo = "%s" } ack_deadline_seconds = %d } -`, topic, subscription, filter, label, deadline) +`, topic, subscription, label, deadline) } func testAccPubsubSubscription_topicOnly(topic string) string { From 8f1a1f4df4303b2edb7ce25063d0bef936d6ccd1 Mon Sep 17 00:00:00 2001 From: Tim O'Connell Date: Wed, 12 Aug 2020 00:53:32 +0800 Subject: [PATCH 6/6] revert remove escaped quotes --- .../terraform/tests/resource_pubsub_subscription_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/terraform/tests/resource_pubsub_subscription_test.go b/third_party/terraform/tests/resource_pubsub_subscription_test.go index c8084b50cfcf..e33c597c97d1 100644 --- a/third_party/terraform/tests/resource_pubsub_subscription_test.go +++ b/third_party/terraform/tests/resource_pubsub_subscription_test.go @@ -221,7 +221,7 @@ resource "google_pubsub_topic" "foo" { resource "google_pubsub_subscription" "foo" { name = "%s" topic = google_pubsub_topic.foo.id - filter = "attributes.foo = "bar"" + filter = "attributes.foo = \"bar\"" labels = { foo = "%s" }