Raw Google Cloud Function example
ADD
gcp-ts-serverless-raw/Pulumi.yaml
+name: serverless
+runtime: nodejs
+description: Basic example of a serverless GCP functions in Python and Go
+template:
+ config:
+ gcp:project:
+ description: The Google Cloud project to deploy into
+ gcp:region:
+ description: The Google Cloud region

ADD
gcp-ts-serverless-raw/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Google Cloud Functions in Python and Go 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.
+
+```bash
+# Create and configure a new stack
+$ pulumi stack init testing
+$ pulumi config set gcp:project <your-gcp-project>
+$ pulumi config set gcp:region <gcp-region>
+
+# Install dependencies
+$ npm install
+
+# Preview and run the deployment
+$ pulumi up
+Previewing changes:
+...
+Performing changes:
+...
+info: 6 changes performed:
+ + 6 resources created
+Update duration: 1m14s
+
+# Test it out
+$ curl $(pulumi stack output pythonEndpoint)
+"Hello World!"
+$ curl $(pulumi stack output goEndpoint)
+"Hello World!"
+
+# Remove the app
+$ pulumi destroy
+```

ADD
gcp-ts-serverless-raw/gofunc/function.go
+package helloworld
+
+import (
+ "fmt"
+ "net/http"
+)
+
+func Handler(w http.ResponseWriter, r *http.Request) {
+
+ w.Header().Set("Content-Type", "text/plain")
+ fmt.Fprintf(w, "Hello World!")
+}

ADD
gcp-ts-serverless-raw/index.ts
+// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
+
+import { asset } from "@pulumi/pulumi";
+import * as gcp from "@pulumi/gcp";
+
+const bucket = new gcp.storage.Bucket("bucket");
+
+// Google Cloud Function in Python
+
+const bucketObjectPython = new gcp.storage.BucketObject("python-zip", {
+ bucket: bucket.name,
+ source: new asset.AssetArchive({
+ ".": new asset.FileArchive("./pythonfunc"),
+ }),
+});
+
+const functionPython = new gcp.cloudfunctions.Function("python-func", {
+ sourceArchiveBucket: bucket.name,
+ runtime: "python37",
+ sourceArchiveObject: bucketObjectPython.name,
+ entryPoint: "handler",
+ triggerHttp: true,
+ availableMemoryMb: 128,
+});
+
+export const pythonEndpoint = functionPython.httpsTriggerUrl;
+
+// Google Cloud Function in Go
+
+const bucketObjectGo = new gcp.storage.BucketObject("go-zip", {
+ bucket: bucket.name,
+ source: new asset.AssetArchive({
+ ".": new asset.FileArchive("./gofunc"),
+ }),
+});
+
+const functionGo = new gcp.cloudfunctions.Function("go-func", {
+ sourceArchiveBucket: bucket.name,
+ runtime: "go111",
+ sourceArchiveObject: bucketObjectGo.name,
+ entryPoint: "Handler",
+ triggerHttp: true,
+ availableMemoryMb: 128,
+});
+
+export const goEndpoint = functionGo.httpsTriggerUrl;

ADD
gcp-ts-serverless-raw/package.json
+{
+ "name": "gcp-ts-serverless-raw",
+ "version": "1.0.0",
+ "dependencies": {
+ "@pulumi/gcp": "latest",
+ "@pulumi/pulumi": "latest"
+ }
+}

ADD
gcp-ts-serverless-raw/pythonfunc/main.py
+def handler(request):
+ headers = {
+ 'Content-Type': 'text/plain'
+ }
+
+ return ('Hello World!', 200, headers)

ADD
gcp-ts-serverless-raw/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es6",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true,
+ "strictNullChecks": true
+ },
+ "files": [
+ "index.ts"
+ ]
+}

Raw Google Cloud Function example (#298)