After reading <https://www.pulumi.com/blog/simple-...
# google-cloud
e
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:
Copy code
// 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:
Copy code
// 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:
Copy code
const eventSource = new gcp.pubsub.Topic("event-source", null, {
	retainOnDelete: true,
	import:
		"/projects/<project>/topics/<topic>",
});
d
hmm. Maybe this?
Copy code
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
Oh yeah. That looks pretty clean. Thanks!