UNPKG

@pulumi/gcp

Version:

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

633 lines • 23.2 kB
"use strict"; // *** 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.Subscription = void 0; const pulumi = __importStar(require("@pulumi/pulumi")); const utilities = __importStar(require("../utilities")); /** * A named resource representing the stream of messages from a single, * specific topic, to be delivered to the subscribing application. * * To get more information about Subscription, see: * * * [API documentation](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions) * * How-to Guides * * [Managing Subscriptions](https://cloud.google.com/pubsub/docs/admin#managing_subscriptions) * * > **Note:** You can retrieve the email of the Google Managed Pub/Sub Service Account used for forwarding * by using the `gcp.projects.ServiceIdentity` resource. * * ## Example Usage * * ### Pubsub Subscription Push * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * ackDeadlineSeconds: 20, * labels: { * foo: "bar", * }, * pushConfig: { * pushEndpoint: "https://example.com/push", * attributes: { * "x-goog-version": "v1", * }, * }, * }); * ``` * ### Pubsub Subscription Pull * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * labels: { * foo: "bar", * }, * messageRetentionDuration: "1200s", * retainAckedMessages: true, * ackDeadlineSeconds: 20, * expirationPolicy: { * ttl: "300000.5s", * }, * retryPolicy: { * minimumBackoff: "10s", * }, * enableMessageOrdering: false, * }); * ``` * ### Pubsub Subscription Pull Filter * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * labels: { * foo: "bar", * }, * filter: ` attributes.foo = \\"foo\\" * AND attributes.bar = \\"bar\\" * `, * ackDeadlineSeconds: 20, * }); * ``` * ### Pubsub Subscription Dead Letter * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const exampleDeadLetter = new gcp.pubsub.Topic("example_dead_letter", {name: "example-topic-dead-letter"}); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * deadLetterPolicy: { * deadLetterTopic: exampleDeadLetter.id, * maxDeliveryAttempts: 10, * }, * }); * ``` * ### Pubsub Subscription Push Bq * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const test = new gcp.bigquery.Dataset("test", {datasetId: "example_dataset"}); * const testTable = new gcp.bigquery.Table("test", { * tableId: "example_table", * datasetId: test.datasetId, * schema: `[ * { * \\"name\\": \\"data\\", * \\"type\\": \\"STRING\\", * \\"mode\\": \\"NULLABLE\\", * \\"description\\": \\"The data\\" * } * ] * `, * deletionProtection: false, * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * bigqueryConfig: { * table: pulumi.interpolate`${testTable.project}.${testTable.datasetId}.${testTable.tableId}`, * }, * }); * const project = gcp.organizations.getProject({}); * ``` * ### Pubsub Subscription Push Bq Table Schema * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const test = new gcp.bigquery.Dataset("test", {datasetId: "example_dataset"}); * const testTable = new gcp.bigquery.Table("test", { * tableId: "example_table", * datasetId: test.datasetId, * schema: `[ * { * \\"name\\": \\"data\\", * \\"type\\": \\"STRING\\", * \\"mode\\": \\"NULLABLE\\", * \\"description\\": \\"The data\\" * } * ] * `, * deletionProtection: false, * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * bigqueryConfig: { * table: pulumi.interpolate`${testTable.project}.${testTable.datasetId}.${testTable.tableId}`, * useTableSchema: true, * }, * }); * const project = gcp.organizations.getProject({}); * ``` * ### Pubsub Subscription Push Bq Service Account * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const bqWriteServiceAccount = new gcp.serviceaccount.Account("bq_write_service_account", { * accountId: "example-bqw", * displayName: "BQ Write Service Account", * }); * const project = gcp.organizations.getProject({}); * const bigqueryMetadataViewer = new gcp.projects.IAMMember("bigquery_metadata_viewer", { * project: project.then(project => project.projectId), * role: "roles/bigquery.metadataViewer", * member: pulumi.interpolate`serviceAccount:${bqWriteServiceAccount.email}`, * }); * const bigqueryDataEditor = new gcp.projects.IAMMember("bigquery_data_editor", { * project: project.then(project => project.projectId), * role: "roles/bigquery.dataEditor", * member: pulumi.interpolate`serviceAccount:${bqWriteServiceAccount.email}`, * }); * const test = new gcp.bigquery.Dataset("test", {datasetId: "example_dataset"}); * const testTable = new gcp.bigquery.Table("test", { * deletionProtection: false, * tableId: "example_table", * datasetId: test.datasetId, * schema: `[ * { * \\"name\\": \\"data\\", * \\"type\\": \\"STRING\\", * \\"mode\\": \\"NULLABLE\\", * \\"description\\": \\"The data\\" * } * ] * `, * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * bigqueryConfig: { * table: pulumi.interpolate`${testTable.project}.${testTable.datasetId}.${testTable.tableId}`, * serviceAccountEmail: bqWriteServiceAccount.email, * }, * }, { * dependsOn: [ * bqWriteServiceAccount, * bigqueryMetadataViewer, * bigqueryDataEditor, * ], * }); * ``` * ### Pubsub Subscription Push Cloudstorage * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.storage.Bucket("example", { * name: "example-bucket", * location: "US", * uniformBucketLevelAccess: true, * }); * const exampleTopic = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const project = gcp.organizations.getProject({}); * const admin = new gcp.storage.BucketIAMMember("admin", { * bucket: example.name, * role: "roles/storage.admin", * member: project.then(project => `serviceAccount:service-${project.number}@gcp-sa-pubsub.iam.gserviceaccount.com`), * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: exampleTopic.id, * cloudStorageConfig: { * bucket: example.name, * filenamePrefix: "pre-", * filenameSuffix: "-_34534", * filenameDatetimeFormat: "YYYY-MM-DD/hh_mm_ssZ", * maxBytes: 1000, * maxDuration: "300s", * maxMessages: 1000, * }, * }, { * dependsOn: [ * example, * admin, * ], * }); * ``` * ### Pubsub Subscription Push Cloudstorage Text * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.storage.Bucket("example", { * name: "example-bucket", * location: "US", * uniformBucketLevelAccess: true, * }); * const exampleTopic = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const project = gcp.organizations.getProject({}); * const admin = new gcp.storage.BucketIAMMember("admin", { * bucket: example.name, * role: "roles/storage.admin", * member: project.then(project => `serviceAccount:service-${project.number}@gcp-sa-pubsub.iam.gserviceaccount.com`), * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: exampleTopic.id, * cloudStorageConfig: { * bucket: example.name, * filenamePrefix: "pre-", * filenameSuffix: "-_87829", * filenameDatetimeFormat: "YYYY-MM-DD/hh_mm_ssZ", * maxBytes: 1000, * maxDuration: "300s", * maxMessages: 1000, * textConfig: {}, * }, * }, { * dependsOn: [ * example, * admin, * ], * }); * ``` * ### Pubsub Subscription Push Cloudstorage Avro * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.storage.Bucket("example", { * name: "example-bucket", * location: "US", * uniformBucketLevelAccess: true, * }); * const exampleTopic = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const project = gcp.organizations.getProject({}); * const admin = new gcp.storage.BucketIAMMember("admin", { * bucket: example.name, * role: "roles/storage.admin", * member: project.then(project => `serviceAccount:service-${project.number}@gcp-sa-pubsub.iam.gserviceaccount.com`), * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: exampleTopic.id, * cloudStorageConfig: { * bucket: example.name, * filenamePrefix: "pre-", * filenameSuffix: "-_44023", * filenameDatetimeFormat: "YYYY-MM-DD/hh_mm_ssZ", * maxBytes: 1000, * maxDuration: "300s", * maxMessages: 1000, * avroConfig: { * writeMetadata: true, * useTopicSchema: true, * }, * }, * }, { * dependsOn: [ * example, * admin, * ], * }); * ``` * ### Pubsub Subscription Push Cloudstorage Service Account * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.storage.Bucket("example", { * name: "example-bucket", * location: "US", * uniformBucketLevelAccess: true, * }); * const exampleTopic = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const storageWriteServiceAccount = new gcp.serviceaccount.Account("storage_write_service_account", { * accountId: "example-stw", * displayName: "Storage Write Service Account", * }); * const admin = new gcp.storage.BucketIAMMember("admin", { * bucket: example.name, * role: "roles/storage.admin", * member: pulumi.interpolate`serviceAccount:${storageWriteServiceAccount.email}`, * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: exampleTopic.id, * cloudStorageConfig: { * bucket: example.name, * filenamePrefix: "pre-", * filenameSuffix: "-_50206", * filenameDatetimeFormat: "YYYY-MM-DD/hh_mm_ssZ", * maxBytes: 1000, * maxDuration: "300s", * serviceAccountEmail: storageWriteServiceAccount.email, * }, * }, { * dependsOn: [ * storageWriteServiceAccount, * example, * admin, * ], * }); * const project = gcp.organizations.getProject({}); * ``` * ### Pubsub Subscription Single Smt * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * messageTransforms: [{ * javascriptUdf: { * functionName: "isYearEven", * code: `function isYearEven(message, metadata) { * const data = JSON.parse(message.data); * return message.year %2 === 0; * } * `, * }, * }], * }); * ``` * ### Pubsub Subscription Multiple Smts * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * messageTransforms: [ * { * javascriptUdf: { * functionName: "redactSSN", * code: `function redactSSN(message, metadata) { * const data = JSON.parse(message.data); * delete data['ssn']; * message.data = JSON.stringify(data); * return message; * } * `, * }, * }, * { * javascriptUdf: { * functionName: "otherFunc", * code: `function otherFunc(message, metadata) { * return null; * } * `, * }, * }, * { * disabled: true, * javascriptUdf: { * functionName: "someSMTWeDisabled", * code: "...", * }, * }, * ], * }); * ``` * ### Pubsub Subscription Tags * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const project = gcp.organizations.getProject({}); * const tagKey = new gcp.tags.TagKey("tag_key", { * parent: project.then(project => project.id), * shortName: "tag_key", * }, { * dependsOn: [example], * }); * const tagValue = new gcp.tags.TagValue("tag_value", { * parent: tagKey.id, * shortName: "tag_value", * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * tags: pulumi.all([tagKey.namespacedName, tagValue.shortName]).apply(([namespacedName, shortName]) => { * [namespacedName]: shortName, * }), * }); * ``` * ### Pubsub Subscription Ai Inference * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as time from "@pulumiverse/time"; * * const example = new gcp.pubsub.Topic("example", {name: "example-topic"}); * const geminiQueryServiceAccount = new gcp.serviceaccount.Account("gemini_query_service_account", { * accountId: "example-sa", * displayName: "Gemini Query Service Account", * }); * const geminiInferenceGet = new gcp.projects.IAMMember("gemini_inference_get", { * project: "my-project-name", * role: "roles/aiplatform.user", * member: pulumi.interpolate`serviceAccount:${geminiQueryServiceAccount.email}`, * }); * const wait120Seconds = new time.Sleep("wait_120_seconds", {createDuration: "120s"}, { * dependsOn: [geminiInferenceGet], * }); * const exampleSubscription = new gcp.pubsub.Subscription("example", { * name: "example-subscription", * topic: example.id, * messageTransforms: [{ * aiInference: { * endpoint: "projects/my-project-name/locations/us-central1/publishers/google/models/gemini-2.5-flash", * unstructuredInference: { * parameters: { * max_tokens: "25000", * }, * }, * serviceAccountEmail: geminiQueryServiceAccount.email, * }, * }], * }, { * dependsOn: [wait120Seconds], * }); * ``` * * ## Import * * Subscription can be imported using any of these accepted formats: * * * `projects/{{project}}/subscriptions/{{name}}` * * `{{project}}/{{name}}` * * `{{name}}` * * When using the `pulumi import` command, Subscription can be imported using one of the formats above. For example: * * ```sh * $ pulumi import gcp:pubsub/subscription:Subscription default projects/{{project}}/subscriptions/{{name}} * $ pulumi import gcp:pubsub/subscription:Subscription default {{project}}/{{name}} * $ pulumi import gcp:pubsub/subscription:Subscription default {{name}} * ``` */ class Subscription extends pulumi.CustomResource { /** * Get an existing Subscription 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 Subscription(name, state, { ...opts, id: id }); } /** @internal */ static __pulumiType = 'gcp:pubsub/subscription:Subscription'; /** * Returns true if the given object is an instance of Subscription. 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'] === Subscription.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["ackDeadlineSeconds"] = state?.ackDeadlineSeconds; resourceInputs["bigqueryConfig"] = state?.bigqueryConfig; resourceInputs["cloudStorageConfig"] = state?.cloudStorageConfig; resourceInputs["deadLetterPolicy"] = state?.deadLetterPolicy; resourceInputs["deletionPolicy"] = state?.deletionPolicy; resourceInputs["effectiveLabels"] = state?.effectiveLabels; resourceInputs["enableExactlyOnceDelivery"] = state?.enableExactlyOnceDelivery; resourceInputs["enableMessageOrdering"] = state?.enableMessageOrdering; resourceInputs["expirationPolicy"] = state?.expirationPolicy; resourceInputs["filter"] = state?.filter; resourceInputs["labels"] = state?.labels; resourceInputs["messageRetentionDuration"] = state?.messageRetentionDuration; resourceInputs["messageTransforms"] = state?.messageTransforms; resourceInputs["name"] = state?.name; resourceInputs["project"] = state?.project; resourceInputs["pulumiLabels"] = state?.pulumiLabels; resourceInputs["pushConfig"] = state?.pushConfig; resourceInputs["retainAckedMessages"] = state?.retainAckedMessages; resourceInputs["retryPolicy"] = state?.retryPolicy; resourceInputs["tags"] = state?.tags; resourceInputs["topic"] = state?.topic; } else { const args = argsOrState; if (args?.topic === undefined && !opts.urn) { throw new Error("Missing required property 'topic'"); } resourceInputs["ackDeadlineSeconds"] = args?.ackDeadlineSeconds; resourceInputs["bigqueryConfig"] = args?.bigqueryConfig; resourceInputs["cloudStorageConfig"] = args?.cloudStorageConfig; resourceInputs["deadLetterPolicy"] = args?.deadLetterPolicy; resourceInputs["deletionPolicy"] = args?.deletionPolicy; resourceInputs["enableExactlyOnceDelivery"] = args?.enableExactlyOnceDelivery; resourceInputs["enableMessageOrdering"] = args?.enableMessageOrdering; resourceInputs["expirationPolicy"] = args?.expirationPolicy; resourceInputs["filter"] = args?.filter; resourceInputs["labels"] = args?.labels; resourceInputs["messageRetentionDuration"] = args?.messageRetentionDuration; resourceInputs["messageTransforms"] = args?.messageTransforms; resourceInputs["name"] = args?.name; resourceInputs["project"] = args?.project; resourceInputs["pushConfig"] = args?.pushConfig; resourceInputs["retainAckedMessages"] = args?.retainAckedMessages; resourceInputs["retryPolicy"] = args?.retryPolicy; resourceInputs["tags"] = args?.tags; resourceInputs["topic"] = args?.topic; resourceInputs["effectiveLabels"] = undefined /*out*/; resourceInputs["pulumiLabels"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); const secretOpts = { additionalSecretOutputs: ["effectiveLabels", "pulumiLabels"] }; opts = pulumi.mergeOptions(opts, secretOpts); super(Subscription.__pulumiType, name, resourceInputs, opts); } } exports.Subscription = Subscription; //# sourceMappingURL=subscription.js.map