@pulumi/gcp
Version:
A Pulumi package for creating and managing Google Cloud Platform resources.
160 lines • 7.42 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Notification = void 0;
const pulumi = __importStar(require("@pulumi/pulumi"));
const utilities = __importStar(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, { ...opts, id: id });
}
/** @internal */
static __pulumiType = 'gcp:storage/notification:Notification';
/**
* 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?.bucket;
resourceInputs["customAttributes"] = state?.customAttributes;
resourceInputs["eventTypes"] = state?.eventTypes;
resourceInputs["notificationId"] = state?.notificationId;
resourceInputs["objectNamePrefix"] = state?.objectNamePrefix;
resourceInputs["payloadFormat"] = state?.payloadFormat;
resourceInputs["selfLink"] = state?.selfLink;
resourceInputs["topic"] = state?.topic;
}
else {
const args = argsOrState;
if (args?.bucket === undefined && !opts.urn) {
throw new Error("Missing required property 'bucket'");
}
if (args?.payloadFormat === undefined && !opts.urn) {
throw new Error("Missing required property 'payloadFormat'");
}
if (args?.topic === undefined && !opts.urn) {
throw new Error("Missing required property 'topic'");
}
resourceInputs["bucket"] = args?.bucket;
resourceInputs["customAttributes"] = args?.customAttributes;
resourceInputs["eventTypes"] = args?.eventTypes;
resourceInputs["objectNamePrefix"] = args?.objectNamePrefix;
resourceInputs["payloadFormat"] = args?.payloadFormat;
resourceInputs["topic"] = args?.topic;
resourceInputs["notificationId"] = undefined /*out*/;
resourceInputs["selfLink"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(Notification.__pulumiType, name, resourceInputs, opts);
}
}
exports.Notification = Notification;
//# sourceMappingURL=notification.js.map