Adds ts example to gcp-ts-serverless-raw
MODIFY
gcp-ts-serverless-raw/README.md
gcp-ts-serverless-raw/README.md
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/gcp-ts-serverless-raw/README.md)
-# Google Cloud Functions in Python and Go Deployed with TypeScript
+# Google Cloud Functions in Python, Go, and TypeScript Deployed with TypeScript
-This example deploys two Google Cloud Functions. "Hello World" functions are implemented in Python and Go. Pulumi program is implemented in TypeScript.
+This example deploys three Google Cloud Functions. "Hello World" functions are implemented in Python, Go, and TypeScript. Pulumi program is implemented in TypeScript.
```bash
# Create and configure a new stack
@@ -28,7 +28,14 @@ $ curl $(pulumi stack output pythonEndpoint)
"Hello World!"
$ curl $(pulumi stack output goEndpoint)
"Hello World!"
+$ curl $(pulumi stack output tsEndpoint)
+"Hello World!"
# Remove the app
$ pulumi destroy
```
+
+## TypeScript Notes
+
+In the `typescriptfunc` folder you'll notice more than a function. Some configuration is needed to inform GCP how to build TypeScript for the Node.js runtime environment. See [this example from Google for more details](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/docs/typescript.md).
+

MODIFY
gcp-ts-serverless-raw/index.ts
gcp-ts-serverless-raw/index.ts
@@ -60,3 +60,31 @@ const goInvoker = new gcp.cloudfunctions.FunctionIamMember("go-invoker", {
});
export const goEndpoint = functionGo.httpsTriggerUrl;
+
+// Google Cloud Function in TypeScript
+
+const tsBucketObject = new gcp.storage.BucketObject("ts-zip", {
+ bucket: bucket.name,
+ source: new asset.AssetArchive({
+ ".": new asset.FileArchive("./typescriptfunc"),
+ }),
+});
+
+const tsFunction = new gcp.cloudfunctions.Function("ts-func", {
+ sourceArchiveBucket: bucket.name,
+ runtime: "nodejs16",
+ sourceArchiveObject: tsBucketObject.name,
+ entryPoint: "handler",
+ triggerHttp: true,
+ availableMemoryMb: 128,
+});
+
+const tsInvoker = new gcp.cloudfunctions.FunctionIamMember("ts-invoker", {
+ project: tsFunction.project,
+ region: tsFunction.region,
+ cloudFunction: tsFunction.name,
+ role: "roles/cloudfunctions.invoker",
+ member: "allUsers",
+});
+
+export const tsEndpoint = tsFunction.httpsTriggerUrl;

ADD
gcp-ts-serverless-raw/typescriptfunc/.gitignore
+node_modules/
+dist/

ADD
gcp-ts-serverless-raw/typescriptfunc/package.json
+{
+ "name": "typescript-function",
+ "version": "1.0.0",
+ "description": "",
+ "main": "dist/index.js",
+ "scripts": {
+ "build": "tsc",
+ "gcp-build": "npm run build"
+ },
+ "keywords": [],
+ "author": "",
+ "license": "ISC",
+ "devDependencies": {
+ "typescript": "^4.9.4"
+ }
+}

ADD
gcp-ts-serverless-raw/typescriptfunc/src/index.ts
+export const handler = async (req: any, res: any) => {
+ res.set("Content-Type", "text/plain");
+ await res.send("Hello World!");
+};

ADD
gcp-ts-serverless-raw/typescriptfunc/tsconfig.json
+{
+ "compilerOptions": {
+ "target": "es2016",
+ "module": "commonjs",
+ "esModuleInterop": true,
+ "strict": true,
+ "outDir": "dist"
+ },
+ "include": ["src/**/*"],
+ "exclude": ["node_modules"]
+}

Adds ts example to gcp-ts-serverless-raw (#1329)