NotificationArgs

data class NotificationArgs(val bucket: Output<String>? = null, val customAttributes: Output<Map<String, String>>? = null, val eventTypes: Output<List<String>>? = null, val objectNamePrefix: Output<String>? = null, val payloadFormat: Output<String>? = null, val topic: Output<String>? = null) : ConvertibleToJava<NotificationArgs>

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 gcp&#46;storage&#46;getProjectServiceAccount 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.

Example Usage

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.storage.StorageFunctions;
import com.pulumi.gcp.storage.inputs.GetProjectServiceAccountArgs;
import com.pulumi.gcp.pubsub.Topic;
import com.pulumi.gcp.pubsub.TopicIAMBinding;
import com.pulumi.gcp.pubsub.TopicIAMBindingArgs;
import com.pulumi.gcp.storage.Bucket;
import com.pulumi.gcp.storage.BucketArgs;
import com.pulumi.gcp.storage.Notification;
import com.pulumi.gcp.storage.NotificationArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var gcsAccount = StorageFunctions.getProjectServiceAccount();
var topic = new Topic("topic");
var binding = new TopicIAMBinding("binding", TopicIAMBindingArgs.builder()
.topic(topic.id())
.role("roles/pubsub.publisher")
.members(String.format("serviceAccount:%s", gcsAccount.applyValue(getProjectServiceAccountResult -> getProjectServiceAccountResult.emailAddress())))
.build());
var bucket = new Bucket("bucket", BucketArgs.builder()
.location("US")
.build());
var notification = new Notification("notification", NotificationArgs.builder()
.bucket(bucket.name())
.payloadFormat("JSON_API_V1")
.topic(topic.id())
.eventTypes(
"OBJECT_FINALIZE",
"OBJECT_METADATA_UPDATE")
.customAttributes(Map.of("new-attribute", "new-attribute-value"))
.build(), CustomResourceOptions.builder()
.dependsOn(binding)
.build());
}
}

Import

Storage notifications can be imported using the notification id in the format <bucket_name>/notificationConfigs/<id> e.g.

$ pulumi import gcp:storage/notification:Notification notification default_bucket/notificationConfigs/102

Constructors

Link copied to clipboard
constructor(bucket: Output<String>? = null, customAttributes: Output<Map<String, String>>? = null, eventTypes: Output<List<String>>? = null, objectNamePrefix: Output<String>? = null, payloadFormat: Output<String>? = null, topic: Output<String>? = null)

Properties

Link copied to clipboard
val bucket: Output<String>? = null

The name of the bucket.

Link copied to clipboard
val customAttributes: Output<Map<String, String>>? = null

A set of key/value attribute pairs to attach to each Cloud PubSub message published for this notification subscription

Link copied to clipboard
val eventTypes: Output<List<String>>? = null

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"

Link copied to clipboard
val objectNamePrefix: Output<String>? = null

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.

Link copied to clipboard
val payloadFormat: Output<String>? = null

The desired content of the Payload. One of "JSON_API_V1" or "NONE".

Link copied to clipboard
val topic: Output<String>? = null

The Cloud PubSub 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.

Functions

Link copied to clipboard
open override fun toJava(): NotificationArgs