A Terraform module for creating a Pub/Sub topic with GCP Monitoring notification channel integration and IAM bindings.
- Create Pub/Sub topic for monitoring alerts
- Automatic GCP Monitoring notification channel creation
- IAM binding for GCP Monitoring service account
- Configurable message retention
- Ready for alert policy integration
The project assumes the following:
- A basic understanding of Git.
- Git version
>= 2.33.0. - An existing GCP IAM user or role with access to create/update/delete resources defined in main.tf.
- GCloud CLI
>= 465.0.0. - A basic understanding of Terraform.
- Terraform version
>= 1.3.0. - (Optional - for local testing) A basic understanding of Make.
- Make version
>= GNU Make 3.81. - Important Note: This project includes a Makefile to speed up local development in Terraform. The
maketargets act as a wrapper around Terraform commands. As such,makehas only been tested/verified on Linux/Mac OS. Though, it is possible to install make using Chocolatey, we do not guarantee this approach as it has not been tested/verified. You may use the commands in the Makefile as a guide to run each Terraform command locally on Windows.
- Make version
Important Note: This project includes a Makefile to speed up local development in Terraform. The make targets act as a wrapper around Terraform commands. As such, make has only been tested/verified on Linux/Mac OS. Though, it is possible to install make using Chocolatey, we do not guarantee this approach as it has not been tested/verified. You may use the commands in the Makefile as a guide to run each Terraform command locally on Windows.
gcloud init # https://cloud.google.com/docs/authentication/gcloud
gcloud auth application-default login
# Copy the example tfvars and customize it
cp examples/simple/examples.tfvars examples/simple/terraform.tfvars
# Edit terraform.tfvars with your values
# Run terraform commands
make plan SVC=simple
make apply SVC=simple
make destroy SVC=simpleContributions are always welcome. As such, this project uses the main branch as the source of truth to track changes.
Step 1. Clone this project.
# Using SSH
$ git clone git@github.com:nurdsoft/terraform-google-pubsub-topic.git
# Using HTTPS
$ git clone https://github.com/nurdsoft/terraform-google-pubsub-topic.gitStep 2. Checkout a feature branch: git checkout -b feature/abc.
Step 3. Validate the change/s locally by executing the steps defined under Test.
Step 4. If testing is successful, commit and push the new change/s to the remote.
$ git add file1 file2 ...
$ git commit -m "Adding some change"
$ git push --set-upstream origin feature/abcStep 5. Once pushed, create a PR and assign it to a member for review.
- Important Note: It can be helpful to attach the
terraform planoutput in the PR.
Step 6. A team member reviews/approves/merges the change/s.
Step 7. Once merged, deploy the required changes as needed.
Step 8. Once deployed, verify that the changes have been deployed.
- If possible, please add a
planoutput using the feature branch so the member reviewing the PR has better visibility into the changes.
module "pubsub_topic" {
source = "git::https://github.com/nurdsoft/terraform-google-pubsub-topic.git?ref=main"
project_id = "my-project"
topic_name = "monitoring-alerts"
}The module provisions the following resources:
| Resource | Description |
|---|---|
google_pubsub_topic |
The Pub/Sub topic that receives alert payloads from GCP Monitoring |
google_monitoring_notification_channel |
A GCP Monitoring notification channel of type pubsub pointing to the topic |
google_pubsub_topic_iam_member |
Grants roles/pubsub.publisher to the GCP Monitoring service account so it can publish alerts to the topic |
| Example | Description |
|---|---|
| simple | Create a Pub/Sub topic with monitoring notification channel |
| Name | Version |
|---|---|
| terraform | >= 1.3 |
| >= 5.0 |
| Name | Version |
|---|---|
| >= 5.0 |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
project_id |
The GCP project ID to deploy resources into | string |
n/a | yes |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
topic_name |
The name of the Pub/Sub topic that receives GCP Monitoring alert notifications | string |
"monitoring-alerts" |
no |
message_retention_duration |
How long to retain unacknowledged messages in the topic (e.g. "86400s" for 1 day) | string |
"86400s" |
no |
notification_channel_display_name |
Display name for the GCP Monitoring notification channel that publishes alerts to the Pub/Sub topic | string |
"Monitoring Alerts Pub/Sub Channel" |
no |
monitoring_publisher_role |
The IAM role granted to the GCP Monitoring service account to allow it to publish alert messages to the Pub/Sub topic | string |
"roles/pubsub.publisher" |
no |
| Name | Description |
|---|---|
topic_id |
The fully-qualified ID of the Pub/Sub topic (e.g. projects/my-project/topics/my-topic) |
topic_name |
The short name of the Pub/Sub topic |
notification_channel_id |
The fully-qualified ID of the GCP Monitoring notification channel |
notification_channel_name |
The resource name of the GCP Monitoring notification channel. Pass this as notification_channels to the alert-policies module |
Module is maintained by Nurdsoft.
Apache 2 Licensed. See LICENSE for full details.