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

Add deadLetterPolicy to Pub/Sub Subscription resource #372

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/resources/google_pubsub_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ 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".

* `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\naccount 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.

* `max_delivery_attempts`: The maximum number of delivery attempts for any message. The value must be between 5 and 100. The number of delivery attempts is defined as 1 + (the sum of number of NACKs and number of times the acknowledgement deadline has been exceeded for the message). A NACK is any call to ModifyAckDeadline with a 0 deadline. Note that client libraries may automatically extend ack_deadlines. This field will be honored on a best effort basis. If this parameter is 0, a default value of 5 is used.


## GCP Permissions

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
* `dead_letter_policies`: an array of `google_pubsub_subscription` dead_letter_policy

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
module GoogleInSpec
module Pubsub
module Property
class SubscriptionDeadLetterPolicy
attr_reader :dead_letter_topic

attr_reader :max_delivery_attempts

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@dead_letter_topic = args['deadLetterTopic']
@max_delivery_attempts = args['maxDeliveryAttempts']
end

def to_s
"#{@parent_identifier} SubscriptionDeadLetterPolicy"
end
end
end
end
end
3 changes: 3 additions & 0 deletions libraries/google_pubsub_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
require 'google/pubsub/property/subscription_dead_letter_policy'
require 'google/pubsub/property/subscription_expiration_policy'
require 'google/pubsub/property/subscription_push_config'
require 'google/pubsub/property/subscription_push_config_oidc_token'
Expand All @@ -33,6 +34,7 @@ class PubsubSubscription < GcpResourceBase
attr_reader :message_retention_duration
attr_reader :retain_acked_messages
attr_reader :expiration_policy
attr_reader :dead_letter_policy

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

def exists?
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(:dead_letter_policies, field: :dead_letter_policy)

filter_table_config.connect(self, :table)

Expand Down Expand Up @@ -78,6 +79,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) },
'deadLetterPolicy' => ->(obj) { return :dead_letter_policy, GoogleInSpec::Pubsub::Property::SubscriptionDeadLetterPolicy.new(obj['deadLetterPolicy'], to_s) },
}
end

Expand Down