I am trying to achieve the following on gcp using terraform.
- A cloud function listens to messages added to a pub/sub topic
- Once a message is added the cloud function is triggered
- If there is an error in processing the message the message is put onto a corresponding dead letter queue.
I'm not sure how to create the subscription for the cloud function which also contains the dead letter policy. At the moment I'm doing the following for the cloud function,
resource "google_cloudfunctions_function" "brw-user-function-item-registered" {
// details
event_trigger {
event_type = "google.pubsub.topic.publish"
resource = "brw-messages"
failure_policy {
retry = false
}
}
// details
}
However there is no option to specify the dead-letter policy in the event_trigger section. If I create a separate google_pubsub_subscription I'm not sure how to give the endpoint to the cloud function. I had a look at what gets created and its actually an endpoint, however I'm not sure how to specify those details in the google_pubsub_subscription
terraform import, to import thegoogle_pubsub_subscriptionautomatically created by your cloud function and then assign it adead_letter_policywith the samepush_config.push_endpoint, the dead letter policy will have no effect because you Cloud Function will ACK acknowledge the pubsub message as soon as it receive it and even if it crashes. So HTTP cloud function a better bet. Otherwise you catch any error in your code and publish the message programatically in the deadletter topic :) - MBHA Phoenix