Google Cloud Storage Notification

This page shows how to write Terraform for Cloud Storage Notification and write them securely.

code-icon

Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.

get-started-button

Terraform Example (google_storage_notification)

Creates a new notification configuration on a specified bucket, establishing a flow of event notifications from GCS to a Cloud Pub/Sub topic. For more information see the official documentation and API. In order to enable notifications, a special Google Cloud Storage service account unique to the project must exist and have the IAM permission "projects.topics.publish" for a Cloud Pub/Sub topic in the project. This service account is not created automatically when a project is created. To ensure the service account exists and obtain its email address for use in granting the correct IAM permission, use the google_storage_project_service_account datasource's email_address value, and see below for an example of enabling notifications by granting the correct IAM permission. See the notifications documentation for more details. >NOTE: This resource can affect your storage IAM policy. If you are using this in the same config as your storage IAM policy resources, consider making this resource dependent on those IAM resources via depends_on. This will safeguard against errors due to IAM race conditions.

Parameters

  • bucket required - string
    • The name of the bucket.

  • custom_attributes optional - map / string
    • A set of key/value attribute pairs to attach to each Cloud Pub/Sub message published for this notification subscription

  • event_types optional - set / string
    • List of event type filters for this notification config. If not specified, Cloud Storage will send notifications for all event types. The valid types are: "OBJECT_FINALIZE", "OBJECT_METADATA_UPDATE", "OBJECT_DELETE", "OBJECT_ARCHIVE"

  • id optionalcomputed - string
  • notification_id requiredcomputed - string
    • The ID of the created notification.

  • object_name_prefix optional - string
    • Specifies a prefix path filter for this notification config. Cloud Storage will only send notifications for objects in this bucket whose names begin with the specified prefix.

  • payload_format required - string
    • The desired content of the Payload. One of "JSON_API_V1" or "NONE".

  • self_link requiredcomputed - string
    • The URI of the created resource.

  • topic required - string
    • The Cloud Pub/Sub topic to which this subscription publishes. Expects either the topic name, assumed to belong to the default GCP provider project, or the project-level name, i.e. projects/my-gcp-project/topics/my-topic or my-topic. If the project is not set in the provider, you will need to use the project-level name.

Example Usage (from GitHub)

github-iconerickertz/csv-exercise
resource "google_storage_notification" "tfer--scoir-002D-csv-002F-cloud-002D-functions-002D-scoir-002D-318015-002D-f681c495f6625f20ap-002D-tp" {
  bucket         = "scoir-csv"
  payload_format = "JSON_API_V1"
  topic          = "//pubsub.googleapis.com/projects/f681c495f6625f20ap-tp/topics/cloud-functions-sbvmyxrfmufpgjr3yv7bx46bbi"
}
github-iconyu-iskw/dbt-artifacts-loader
resource "google_storage_notification" "notification" {
  bucket         = google_storage_bucket.dbt_artifacts.name
  payload_format = "JSON_API_V1"
  topic          = google_pubsub_topic.dbt_artifacts_notification.id
  event_types    = ["OBJECT_FINALIZE"]

github-iconniveklabs/google
resource "google_storage_notification" "this" {
  bucket             = var.bucket
  custom_attributes  = var.custom_attributes
  event_types        = var.event_types
  object_name_prefix = var.object_name_prefix
  payload_format     = var.payload_format

Frequently asked questions

What is Google Cloud Storage Notification?

Google Cloud Storage Notification is a resource for Cloud Storage of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud Storage Notification?

For Terraform, the erickertz/csv-exercise, yu-iskw/dbt-artifacts-loader and niveklabs/google source code examples are useful. See the Terraform Example section for further details.