Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the Google PubSub terraform script. #1946

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions src/main/terraform/gcloud/modules/pubsub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Google PubSub

A reusable Terraform module that creates a Pub/Sub Topic with an associated Subscription.
28 changes: 28 additions & 0 deletions src/main/terraform/gcloud/modules/pubsub/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.message_retention_duration
}
23 changes: 23 additions & 0 deletions src/main/terraform/gcloud/modules/pubsub/outputs.tf
Original file line number Diff line number Diff line change
@@ -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"
}
43 changes: 43 additions & 0 deletions src/main/terraform/gcloud/modules/pubsub/variables.tf
Original file line number Diff line number Diff line change
@@ -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 "message_retention_duration" {
description = "The duration (in seconds) for which Pub/Sub retains unacknowledged messages."
type = string
default = "604800s"
}

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 "undelivered_messages_threshold" {
description = "Threshold for undelivered messages that triggers an alert."
type = number
default = 50
}
22 changes: 22 additions & 0 deletions src/main/terraform/gcloud/modules/pubsub/versions.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}