https://pulumi.com logo
Title
e

eager-keyboard-30823

01/19/2023, 5:38 PM
After reading https://www.pulumi.com/blog/simple-serverless-programming-with-google-cloud-functions-and-pulumi/, I started wondering whether there was a way to easily create a function for pubsub, but where the topic already exists and for ownership reasons shouldn’t be imported? e.g. Before:
// Create a PubSub Topic
let requests = new gcp.pubsub.Topic("requests");
requests.onMessagePublished("newMessage", (data) => {
    // Print out a log message for every message on the Topic.
    // Change this code to fit your needs!
    console.log(Buffer.from(data.data, "base64").toString());
});
After:
// Create a PubSub Topic
let requests = await gcp.pubsub.getTopic("requests");
/// ???
requests.onMessagePublished("newMessage", (data) => {
    // Print out a log message for every message on the Topic.
    // Change this code to fit your needs!
    console.log(Buffer.from(data.data, "base64").toString());
});
Might this be acceptable:
const eventSource = new gcp.pubsub.Topic("event-source", null, {
	retainOnDelete: true,
	import:
		"/projects/<project>/topics/<topic>",
});
d

dry-keyboard-94795

01/19/2023, 5:56 PM
hmm. Maybe this?
Topic.prototype.onMessagePublished(requests, ...)
Though looking at the code, you may as well use
cloudfunctions.CallbackFunction
directly. https://github.com/pulumi/pulumi-gcp/blob/master/sdk/nodejs/pubsub/zMixins.ts#L82
e

eager-keyboard-30823

01/19/2023, 5:59 PM
Oh yeah. That looks pretty clean. Thanks!