Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add new field filter to pubsub. (#3759) (#431)
Browse files Browse the repository at this point in the history
* Add new field filter to pubsub.

Fixes: hashicorp/terraform-provider-google#6727

* Fixed filter name, it was improperly set.

* add filter key to pubsub subscription unit test

* spaces not tabs!

* hardcode filter value in test

* revert remove escaped quotes

Co-authored-by: Tim O'Connell <hi@timoconnell.co.uk>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Tim O'Connell <hi@timoconnell.co.uk>
  • Loading branch information
modular-magician and tim-codes authored Aug 11, 2020
1 parent a60496e commit b4e8635
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/resources/google_pubsub_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Properties that can be accessed from the `google_pubsub_subscription` resource:

* `ttl`: Specifies the "time-to-live" duration for an associated resource. The resource expires if it is not active for a period of ttl. 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".

* `filter`: 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.

* `dead_letter_policy`: A policy that specifies the conditions for dead lettering messages in this subscription. If dead_letter_policy is not set, dead lettering is disabled. The Cloud Pub/Sub service account associated with this subscriptions's parent project (i.e., service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have permission to Acknowledge() messages on this subscription.

* `dead_letter_topic`: The name of the topic to which dead letter messages should be published. Format is `projects/{project}/topics/{topic}`. The Cloud Pub/Sub service account associated with the enclosing subscription's parent project (i.e., service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have permission to Publish() to this topic. The operation will fail if the topic does not exist. Users should ensure that there is a subscription attached to this topic since messages published to a topic with no subscriptions are lost.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/google_pubsub_subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ See [google_pubsub_subscription.md](google_pubsub_subscription.md) for more deta
* `message_retention_durations`: an array of `google_pubsub_subscription` message_retention_duration
* `retain_acked_messages`: an array of `google_pubsub_subscription` retain_acked_messages
* `expiration_policies`: an array of `google_pubsub_subscription` expiration_policy
* `filters`: an array of `google_pubsub_subscription` filter
* `dead_letter_policies`: an array of `google_pubsub_subscription` dead_letter_policy

## Filter Criteria
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_pubsub_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PubsubSubscription < GcpResourceBase
attr_reader :message_retention_duration
attr_reader :retain_acked_messages
attr_reader :expiration_policy
attr_reader :filter
attr_reader :dead_letter_policy

def initialize(params)
Expand All @@ -52,6 +53,7 @@ def parse
@message_retention_duration = @fetched['messageRetentionDuration']
@retain_acked_messages = @fetched['retainAckedMessages']
@expiration_policy = GoogleInSpec::Pubsub::Property::SubscriptionExpirationPolicy.new(@fetched['expirationPolicy'], to_s)
@filter = @fetched['filter']
@dead_letter_policy = GoogleInSpec::Pubsub::Property::SubscriptionDeadLetterPolicy.new(@fetched['deadLetterPolicy'], to_s)
end

Expand Down
2 changes: 2 additions & 0 deletions libraries/google_pubsub_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PubsubSubscriptions < GcpResourceBase
filter_table_config.add(:message_retention_durations, field: :message_retention_duration)
filter_table_config.add(:retain_acked_messages, field: :retain_acked_messages)
filter_table_config.add(:expiration_policies, field: :expiration_policy)
filter_table_config.add(:filters, field: :filter)
filter_table_config.add(:dead_letter_policies, field: :dead_letter_policy)

filter_table_config.connect(self, :table)
Expand Down Expand Up @@ -79,6 +80,7 @@ def transformers
'messageRetentionDuration' => ->(obj) { return :message_retention_duration, obj['messageRetentionDuration'] },
'retainAckedMessages' => ->(obj) { return :retain_acked_messages, obj['retainAckedMessages'] },
'expirationPolicy' => ->(obj) { return :expiration_policy, GoogleInSpec::Pubsub::Property::SubscriptionExpirationPolicy.new(obj['expirationPolicy'], to_s) },
'filter' => ->(obj) { return :filter, obj['filter'] },
'deadLetterPolicy' => ->(obj) { return :dead_letter_policy, GoogleInSpec::Pubsub::Property::SubscriptionDeadLetterPolicy.new(obj['deadLetterPolicy'], to_s) },
}
end
Expand Down

0 comments on commit b4e8635

Please sign in to comment.