diff --git a/products/pubsub/api.yaml b/products/pubsub/api.yaml index 155a22658ef5..d6c06d8341c5 100644 --- a/products/pubsub/api.yaml +++ b/products/pubsub/api.yaml @@ -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. diff --git a/products/pubsub/terraform.yaml b/products/pubsub/terraform.yaml index b1d475e28e8d..b620ca35159b 100644 --- a/products/pubsub/terraform.yaml +++ b/products/pubsub/terraform.yaml @@ -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}` diff --git a/templates/terraform/examples/pubsub_subscription_dead_letter.tf.erb b/templates/terraform/examples/pubsub_subscription_dead_letter.tf.erb new file mode 100644 index 000000000000..e7274d16f004 --- /dev/null +++ b/templates/terraform/examples/pubsub_subscription_dead_letter.tf.erb @@ -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 + } +}