UNPKG

@pulumi/gcp

Version:

A Pulumi package for creating and managing Google Cloud Platform resources.

137 lines 6.71 kB
"use strict"; // *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Notification = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * 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](https://cloud.google.com/storage/docs/pubsub-notifications) * and * [API](https://cloud.google.com/storage/docs/json_api/v1/notifications). * * 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.storage.getProjectServiceAccount`](https://www.terraform.io/docs/providers/google/d/storage_project_service_account.html) * datasource's `emailAddress` value, and see below for an example of enabling notifications by granting the correct IAM permission. * See [the notifications documentation](https://cloud.google.com/storage/docs/gsutil/commands/notification) 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 `dependsOn`. This will safeguard against errors due to IAM race conditions. * * ## Example Usage * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * // Enable notifications by giving the correct IAM permission to the unique service account. * const gcsAccount = gcp.storage.getProjectServiceAccount({}); * const topic = new gcp.pubsub.Topic("topic", {name: "default_topic"}); * const binding = new gcp.pubsub.TopicIAMBinding("binding", { * topic: topic.id, * role: "roles/pubsub.publisher", * members: [gcsAccount.then(gcsAccount => `serviceAccount:${gcsAccount.emailAddress}`)], * }); * // End enabling notifications * const bucket = new gcp.storage.Bucket("bucket", { * name: "default_bucket", * location: "US", * }); * const notification = new gcp.storage.Notification("notification", { * bucket: bucket.name, * payloadFormat: "JSON_API_V1", * topic: topic.id, * eventTypes: [ * "OBJECT_FINALIZE", * "OBJECT_METADATA_UPDATE", * ], * customAttributes: { * "new-attribute": "new-attribute-value", * }, * }, { * dependsOn: [binding], * }); * ``` * * ## Import * * Storage notifications can be imported using any of these accepted formats: * * * `{{bucket_name}}/notificationConfigs/{{id}}` * * When using the `pulumi import` command, Storage notifications can be imported using one of the formats above. For example: * * ```sh * $ pulumi import gcp:storage/notification:Notification default {{bucket_name}}/notificationConfigs/{{id}} * ``` */ class Notification extends pulumi.CustomResource { /** * Get an existing Notification resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new Notification(name, state, Object.assign(Object.assign({}, opts), { id: id })); } /** * Returns true if the given object is an instance of Notification. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === Notification.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["bucket"] = state ? state.bucket : undefined; resourceInputs["customAttributes"] = state ? state.customAttributes : undefined; resourceInputs["eventTypes"] = state ? state.eventTypes : undefined; resourceInputs["notificationId"] = state ? state.notificationId : undefined; resourceInputs["objectNamePrefix"] = state ? state.objectNamePrefix : undefined; resourceInputs["payloadFormat"] = state ? state.payloadFormat : undefined; resourceInputs["selfLink"] = state ? state.selfLink : undefined; resourceInputs["topic"] = state ? state.topic : undefined; } else { const args = argsOrState; if ((!args || args.bucket === undefined) && !opts.urn) { throw new Error("Missing required property 'bucket'"); } if ((!args || args.payloadFormat === undefined) && !opts.urn) { throw new Error("Missing required property 'payloadFormat'"); } if ((!args || args.topic === undefined) && !opts.urn) { throw new Error("Missing required property 'topic'"); } resourceInputs["bucket"] = args ? args.bucket : undefined; resourceInputs["customAttributes"] = args ? args.customAttributes : undefined; resourceInputs["eventTypes"] = args ? args.eventTypes : undefined; resourceInputs["objectNamePrefix"] = args ? args.objectNamePrefix : undefined; resourceInputs["payloadFormat"] = args ? args.payloadFormat : undefined; resourceInputs["topic"] = args ? args.topic : undefined; resourceInputs["notificationId"] = undefined /*out*/; resourceInputs["selfLink"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(Notification.__pulumiType, name, resourceInputs, opts); } } exports.Notification = Notification; /** @internal */ Notification.__pulumiType = 'gcp:storage/notification:Notification'; //# sourceMappingURL=notification.js.map