diff --git a/src/main/terraform/gcloud/modules/pubsub/README.md b/src/main/terraform/gcloud/modules/pubsub/README.md new file mode 100644 index 00000000000..d7d829fc3d6 --- /dev/null +++ b/src/main/terraform/gcloud/modules/pubsub/README.md @@ -0,0 +1,3 @@ +# Google PubSub + +A reusable Terraform module that creates a Pub/Sub Topic with an associated Subscription. \ No newline at end of file diff --git a/src/main/terraform/gcloud/modules/pubsub/main.tf b/src/main/terraform/gcloud/modules/pubsub/main.tf new file mode 100644 index 00000000000..8e5bb74a850 --- /dev/null +++ b/src/main/terraform/gcloud/modules/pubsub/main.tf @@ -0,0 +1,36 @@ +# Copyright 2024 The Cross-Media Measurement Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +data "google_project" "project" {} + +resource "google_pubsub_topic" "topic" { + project = data.google_project.project.name + name = var.topic_name +} + +resource "google_pubsub_subscription" "subscription" { + name = var.subscription_name + topic = google_pubsub_topic.topic.id + + ack_deadline_seconds = var.ack_deadline_seconds + message_retention_duration = var.subscription_queue_retention_period + + dead_letter_policy { + dead_letter_topic = google_pubsub_topic.topic.id + max_delivery_attempts = var.max_delivery_attempts + } + + enable_exactly_once_delivery = true + +} diff --git a/src/main/terraform/gcloud/modules/pubsub/outputs.tf b/src/main/terraform/gcloud/modules/pubsub/outputs.tf new file mode 100644 index 00000000000..f175bff6168 --- /dev/null +++ b/src/main/terraform/gcloud/modules/pubsub/outputs.tf @@ -0,0 +1,23 @@ +# Copyright 2024 The Cross-Media Measurement Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +output "pubsub_topic" { + value = google_pubsub_topic.topic.name + description = "Name of the created Pub/Sub topic" +} + +output "pubsub_subscription" { + value = google_pubsub_subscription.subscription.name + description = "Name of the created Pub/Sub subscription" +} diff --git a/src/main/terraform/gcloud/modules/pubsub/variables.tf b/src/main/terraform/gcloud/modules/pubsub/variables.tf new file mode 100644 index 00000000000..693c49d6557 --- /dev/null +++ b/src/main/terraform/gcloud/modules/pubsub/variables.tf @@ -0,0 +1,43 @@ +# Copyright 2024 The Cross-Media Measurement Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +variable "topic_name" { + description = "Name of the Pub/Sub topic" + type = string + nullable = false +} + +variable "subscription_name" { + description = "Name of the Pub/Sub subscription" + type = string + nullable = false +} + +variable "subscription_queue_retention_period" { + description = "The duration (in seconds) for which the subscription queue retains unacknowledged messages." + type = string + default = null +} + +variable "ack_deadline_seconds" { + description = "The time (in seconds) allowed for subscribers to acknowledge messages. If the acknowledgment period is not extended or the message is not acknowledged within this time, the message will be re-delivered." + type = number + default = null +} + +variable "max_delivery_attempts" { + description = "The maximum number of delivery attempts for a message before it is routed to the dead letter queue." + type = number + default = null +} diff --git a/src/main/terraform/gcloud/modules/pubsub/versions.tf b/src/main/terraform/gcloud/modules/pubsub/versions.tf new file mode 100644 index 00000000000..3ab0473a092 --- /dev/null +++ b/src/main/terraform/gcloud/modules/pubsub/versions.tf @@ -0,0 +1,22 @@ +# Copyright 2024 The Cross-Media Measurement Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = ">= 6.12.0" + } + } +}