Skip to content

Commit

Permalink
Add deadLetterPolicy to Pub/Sub Subscription resource (GoogleCloudPla…
Browse files Browse the repository at this point in the history
…tform#3305)

* Add deadLetterPolicy to Pub/Sub subscription resource

* fix: disable allow_empty_objects, fix docstring, add example

* fix: set max_delivery_attempts

* fix: block and topic name
  • Loading branch information
shaxbee authored and Nathan Klish committed May 18, 2020
1 parent 02560fa commit c6d8659
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
42 changes: 42 additions & 0 deletions products/pubsub/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,45 @@ 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::NestedObject
name: 'deadLetterPolicy'
send_empty_value: true
description: |
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.
properties:
- !ruby/object:Api::Type::String
name: 'deadLetterTopic'
description: |
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.
- !ruby/object:Api::Type::Integer
name: 'maxDeliveryAttempts'
description: |
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.
6 changes: 6 additions & 0 deletions products/pubsub/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides
topic_project: "topic-project"
subscription_name: "example-subscription"
subscription_project: "subscription-project"
- !ruby/object:Provider::Terraform::Examples
name: "pubsub_subscription_dead_letter"
primary_resource_id: "example"
vars:
topic_name: "example-topic"
subscription_name: "example-subscription"
docs: !ruby/object:Provider::Terraform::Docs
attributes: |
* `path`: Path of the subscription in the format `projects/{project}/subscriptions/{name}`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "google_pubsub_topic" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['topic_name'] %>"
}

resource "google_pubsub_topic" "<%= ctx[:primary_resource_id] %>_dead_letter" {
name = "<%= ctx[:vars]['topic_name'] %>-dead-letter"
}

resource "google_pubsub_subscription" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['subscription_name'] %>"
topic = google_pubsub_topic.<%= ctx[:primary_resource_id] %>.name

dead_letter_policy {
dead_letter_topic = google_pubsub_topic.<%= ctx[:primary_resource_id] %>_dead_letter.id
max_delivery_attempts = 10
}
}

0 comments on commit c6d8659

Please sign in to comment.