UNPKG

@pulumi/gcp

Version:

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

446 lines • 16.9 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.Subscription = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = 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: "-_41150", * filenameDatetimeFormat: "YYYY-MM-DD/hh_mm_ssZ", * maxBytes: 1000, * maxDuration: "300s", * maxMessages: 1000, * }, * }, { * 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: "-_89313", * 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: "-_60646", * filenameDatetimeFormat: "YYYY-MM-DD/hh_mm_ssZ", * maxBytes: 1000, * maxDuration: "300s", * serviceAccountEmail: storageWriteServiceAccount.email, * }, * }, { * dependsOn: [ * storageWriteServiceAccount, * example, * admin, * ], * }); * const project = gcp.organizations.getProject({}); * ``` * * ## 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}} * ``` * * ```sh * $ pulumi import gcp:pubsub/subscription:Subscription default {{project}}/{{name}} * ``` * * ```sh * $ 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, Object.assign(Object.assign({}, opts), { id: id })); } /** * 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 ? state.ackDeadlineSeconds : undefined; resourceInputs["bigqueryConfig"] = state ? state.bigqueryConfig : undefined; resourceInputs["cloudStorageConfig"] = state ? state.cloudStorageConfig : undefined; resourceInputs["deadLetterPolicy"] = state ? state.deadLetterPolicy : undefined; resourceInputs["effectiveLabels"] = state ? state.effectiveLabels : undefined; resourceInputs["enableExactlyOnceDelivery"] = state ? state.enableExactlyOnceDelivery : undefined; resourceInputs["enableMessageOrdering"] = state ? state.enableMessageOrdering : undefined; resourceInputs["expirationPolicy"] = state ? state.expirationPolicy : undefined; resourceInputs["filter"] = state ? state.filter : undefined; resourceInputs["labels"] = state ? state.labels : undefined; resourceInputs["messageRetentionDuration"] = state ? state.messageRetentionDuration : undefined; resourceInputs["name"] = state ? state.name : undefined; resourceInputs["project"] = state ? state.project : undefined; resourceInputs["pulumiLabels"] = state ? state.pulumiLabels : undefined; resourceInputs["pushConfig"] = state ? state.pushConfig : undefined; resourceInputs["retainAckedMessages"] = state ? state.retainAckedMessages : undefined; resourceInputs["retryPolicy"] = state ? state.retryPolicy : undefined; resourceInputs["topic"] = state ? state.topic : undefined; } else { const args = argsOrState; if ((!args || args.topic === undefined) && !opts.urn) { throw new Error("Missing required property 'topic'"); } resourceInputs["ackDeadlineSeconds"] = args ? args.ackDeadlineSeconds : undefined; resourceInputs["bigqueryConfig"] = args ? args.bigqueryConfig : undefined; resourceInputs["cloudStorageConfig"] = args ? args.cloudStorageConfig : undefined; resourceInputs["deadLetterPolicy"] = args ? args.deadLetterPolicy : undefined; resourceInputs["enableExactlyOnceDelivery"] = args ? args.enableExactlyOnceDelivery : undefined; resourceInputs["enableMessageOrdering"] = args ? args.enableMessageOrdering : undefined; resourceInputs["expirationPolicy"] = args ? args.expirationPolicy : undefined; resourceInputs["filter"] = args ? args.filter : undefined; resourceInputs["labels"] = args ? args.labels : undefined; resourceInputs["messageRetentionDuration"] = args ? args.messageRetentionDuration : undefined; resourceInputs["name"] = args ? args.name : undefined; resourceInputs["project"] = args ? args.project : undefined; resourceInputs["pushConfig"] = args ? args.pushConfig : undefined; resourceInputs["retainAckedMessages"] = args ? args.retainAckedMessages : undefined; resourceInputs["retryPolicy"] = args ? args.retryPolicy : undefined; resourceInputs["topic"] = args ? args.topic : undefined; 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; /** @internal */ Subscription.__pulumiType = 'gcp:pubsub/subscription:Subscription'; //# sourceMappingURL=subscription.js.map