GCP-Native port of ts-functions
ADD
gcp-native-ts-functions/Pulumi.yaml
+name: gcp-functions
+runtime: nodejs
+description: GCP Functions example
+template:
+ config:
+ gcp:project:
+ description: The Google Cloud project to deploy into
+ gcp:region:
+ description: The Google Cloud region

ADD
gcp-native-ts-functions/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Google Cloud Functions
+
+An example of deploying an HTTP Google Cloud Function endpoint using GCP Native provider and TypeScript.
+
+## Prerequisites
+
+0. [Ensure you have the latest Node.js and NPM](https://nodejs.org/en/download/)
+2. [Install the Pulumi CLI](https://www.pulumi.com/docs/get-started/install/)
+3. [Configure Pulumi to access your GCP account](https://www.pulumi.com/docs/intro/cloud-providers/gcp/setup/)
+
+## Running the App
+
+1. Restore NPM dependencies:
+
+ ```
+ $ npm install
+ ```
+
+2. Create a new stack:
+
+ ```
+ $ pulumi stack init gcp-fn
+ ```
+
+3. Configure your GCP project and region:
+
+ ```
+ $ pulumi config set gcp-native:project <projectname>
+ $ pulumi config set gcp-native:region <region>
+ ```
+
+4. Run `pulumi up` to preview and deploy changes:
+
+ ```
+ $ pulumi up
+ Previewing changes:
+ ...
+
+ Performing changes:
+ ...
+ info: 6 changes performed:
+ + 6 resources created
+ Update duration: 39.65130324s
+ ```
+
+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
+ ...
+ ```

ADD
gcp-native-ts-functions/index.ts
+// Copyright 2016-2021, Pulumi Corporation.
+
+import * as gcp from "@pulumi/gcp-native";
+import * as pulumi from "@pulumi/pulumi";
+import * as random from "@pulumi/random";
+
+const config = new pulumi.Config("gcp-native");
+const project = config.require("project");
+const region = config.require("region");
+
+const randomString = new random.RandomString("name", {
+ upper: false,
+ number: false,
+ special: false,
+ length: 8,
+});
+
+const bucketName = pulumi.interpolate`bucket-${randomString.result}`;
+const bucket = new gcp.storage.v1.Bucket("bucket", {
+ project: project,
+ bucket: bucketName,
+ name: bucketName,
+});
+
+const archiveName = "zip";
+const bucketObject = new gcp.storage.v1.BucketObject(archiveName, {
+ object: archiveName,
+ name: archiveName,
+ bucket: bucket.name,
+ source: new pulumi.asset.AssetArchive({
+ ".": new pulumi.asset.FileArchive("./pythonfunc"),
+ }),
+});
+
+const functionName = pulumi.interpolate`func-${randomString.result}`;
+const func = new gcp.cloudfunctions.v1.Function("function-py", {
+ projectsId: project,
+ locationsId: region,
+ functionsId: functionName,
+ name: pulumi.interpolate`projects/${project}/locations/${region}/functions/${functionName}`,
+ sourceArchiveUrl: pulumi.interpolate`gs://${bucket.name}/${bucketObject.name}`,
+ httpsTrigger: {},
+ entryPoint: "handler",
+ timeout: "60s",
+ availableMemoryMb: 128,
+ runtime: "python37",
+ ingressSettings: "ALLOW_ALL",
+});
+
+const invoker = new gcp.cloudfunctions.v1.FunctionIamPolicy("function-py-iam", {
+ projectsId: project,
+ locationsId: region,
+ functionsId: functionName, // func.name returns the long `projects/foo/locations/bat/functions/buzz` name which doesn't suit here
+ bindings: [
+ {
+ members: ["allUsers"],
+ role: "roles/cloudfunctions.invoker",
+ },
+ ],
+}, { dependsOn: func});
+
+export const functionUrl = func.httpsTrigger.url;

ADD
gcp-native-ts-functions/package.json
+{
+ "name": "gcp-ts-functions",
+ "version": "1.0.0",
+ "devDependencies": {
+ "@types/node": "^8.0.0",
+ "@types/express": "^4.16.0"
+ },
+ "dependencies": {
+ "@pulumi/gcp-native": "^0.0.2a",
+ "@pulumi/pulumi": "^3.0.0a",
+ "@pulumi/random": "^4.0.0a"
+ }
+}

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

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

GCP-Native port of ts-functions