Update GCP function example to new APIs
MODIFY
gcp-ts-functions/README.md
gcp-ts-functions/README.md
# GCP Functions
-An example Pulumi component that deploys a TypeScript function to Google Cloud Functions.
+An example of deploying an HTTP Google Cloud Function endpoint using TypeScript.
+
+## Prerequisites
+
+0. [Ensure you have the latest Node.js and NPM](https://nodejs.org/en/download/)
+2. [Install the Pulumi CLI](https://pulumi.io/quickstart/install.html)
+3. [Configure Pulumi to access your GCP account](https://pulumi.io/quickstart/gcp/setup.html)
## Running the App
-1. Create a new stack:
+1. Restore NPM dependencies:
```
- $ pulumi stack init gcp-fn
+ $ npm install
```
-1. Configure GCP project and region:
+2. Create a new stack:
```
- $ pulumi config set gcp:project <projectname>
- $ pulumi config set gcp:region <region>
+ $ pulumi stack init gcp-fn
```
-1. Restore NPM dependencies:
+3. Configure your GCP project and region:
```
- $ npm install
+ $ pulumi config set gcp:project <projectname>
+ $ pulumi config set gcp:region <region>
```
-1. Run `pulumi up` to preview and deploy changes:
+4. Run `pulumi up` to preview and deploy changes:
```
$ pulumi up
@@ -39,12 +45,20 @@ An example Pulumi component that deploys a TypeScript function to Google Cloud F
Update duration: 39.65130324s
```
-1. Check the deployed function endpoint:
+5. Check the deployed function endpoint:
```
$ pulumi stack output url
https://us-central1-pulumi-development.cloudfunctions.net/greeting-function-7f95447
$ curl "$(pulumi stack output url)"
Greetings from Google Cloud Functions!
+ ```
+
+6. Clean up your GCP and Pulumi resources:
+
+ ```
+ $ pulumi destroy
+ ...
+ $ pulumi stack rm
...
```

DELETE
gcp-ts-functions/gcpFunction.ts
-import * as pulumi from "@pulumi/pulumi";
-import * as gcp from "@pulumi/gcp";
-import * as express from "express";
-
-// Note: The `HttpFunction` helper defined here will in the future be made available via a `@pulumi/gcp-serverless`
-// package, and extended to support additional configuration options similar to that available in
-// `@pulumi/aws-serverless`.
-
-// The callback type of a handler for a Google Cloud Functions HTTP Function.
-// See https://cloud.google.com/functions/docs/writing/http.
-export type HttpHandler = (req: express.Request, resp: express.Response) => void;
-
-// HttpFunction creates a Google Cloud Function HTTP Function from the provided JavaScript callback.
-export class HttpFunction extends pulumi.ComponentResource {
- public bucket: gcp.storage.Bucket;
- public bucketObject: gcp.storage.BucketObject;
- public function: gcp.cloudfunctions.Function;
-
- public httpsTriggerUrl: pulumi.Output<string>;
-
- constructor(name: string, handler: HttpHandler, options?: pulumi.ResourceOptions) {
- super("gcp:serverless:HttpFunction", name, {}, options);
-
- // Serialize JavaScript callback to text
- const serializedFunction = pulumi.runtime.serializeFunction(handler);
- const functionText = serializedFunction.then(x => x.text);
- const functionEntryPoint = serializedFunction.then(x => x.exportName);
-
- // Create a bucket and object to store the function ZIP file
- this.bucket = new gcp.storage.Bucket(`${name}-bucket`, {}, { parent: this });
- this.bucketObject = new gcp.storage.BucketObject(`${name}-object`, {
- bucket: this.bucket.name,
- source: new pulumi.asset.AssetArchive({
- "index.js": new pulumi.asset.StringAsset(functionText),
- }),
- }, { parent: this });
-
- // Create the Function resource
- this.function = new gcp.cloudfunctions.Function(`${name}-function`, {
- sourceArchiveBucket: this.bucket.name,
- sourceArchiveObject: this.bucketObject.name,
- entryPoint: functionEntryPoint,
- triggerHttp: true,
- }, { parent: this });
-
- // Make the trigger URL easily accessible
- this.httpsTriggerUrl = this.function.httpsTriggerUrl;
- }
-}
\ No newline at end of file

MODIFY
gcp-ts-functions/index.ts
gcp-ts-functions/index.ts
-import * as gcpFunction from "./gcpFunction";
+import * as gcp from "@pulumi/gcp";
-let greetingFunction = new gcpFunction.HttpFunction("greeting", (req, res) => {
+let greeting = new gcp.cloudfunctions.HttpCallbackFunction("greeting", (req, res) => {
res.send(`Greetings from ${req.body.name || 'Google Cloud Functions'}!`);
});
-export let url = greetingFunction.httpsTriggerUrl;
+export let url = greeting.httpsTriggerUrl;

Update GCP function example to new APIs (#270)