|
| 1 | +// Copyright 2016-2021, Pulumi Corporation. |
| 2 | + |
| 3 | +import * as gcloud from "@pulumi/google-native"; |
| 4 | +import * as pulumi from "@pulumi/pulumi"; |
| 5 | +import * as random from "@pulumi/random"; |
| 6 | + |
| 7 | +const config = new pulumi.Config("google-native"); |
| 8 | +const project = config.require("project"); |
| 9 | +const region = config.require("region"); |
| 10 | + |
| 11 | +const randomString = new random.RandomString("name", { |
| 12 | + upper: false, |
| 13 | + number: false, |
| 14 | + special: false, |
| 15 | + length: 8, |
| 16 | +}); |
| 17 | + |
| 18 | +const bucketName = pulumi.interpolate`bucket-${randomString.result}`; |
| 19 | +const bucket = new gcloud.storage.v1.Bucket("bucket", { |
| 20 | + project: project, |
| 21 | + bucket: bucketName, |
| 22 | + name: bucketName, |
| 23 | +}); |
| 24 | + |
| 25 | +const archiveName = "zip"; |
| 26 | +const bucketObject = new gcloud.storage.v1.BucketObject(archiveName, { |
| 27 | + object: archiveName, |
| 28 | + name: archiveName, |
| 29 | + bucket: bucket.name, |
| 30 | + source: new pulumi.asset.AssetArchive({ |
| 31 | + ".": new pulumi.asset.FileArchive("./pythonfunc"), |
| 32 | + }), |
| 33 | +}); |
| 34 | + |
| 35 | +const functionName = pulumi.interpolate`func-${randomString.result}`; |
| 36 | +const func = new gcloud.cloudfunctions.v1.Function("function-py", { |
| 37 | + projectsId: project, |
| 38 | + locationsId: region, |
| 39 | + functionsId: functionName, |
| 40 | + name: pulumi.interpolate`projects/${project}/locations/${region}/functions/${functionName}`, |
| 41 | + sourceArchiveUrl: pulumi.interpolate`gs://${bucket.name}/${bucketObject.name}`, |
| 42 | + httpsTrigger: {}, |
| 43 | + entryPoint: "handler", |
| 44 | + timeout: "60s", |
| 45 | + availableMemoryMb: 128, |
| 46 | + runtime: "python37", |
| 47 | + ingressSettings: "ALLOW_ALL", |
| 48 | +}); |
| 49 | + |
| 50 | +const invoker = new gcloud.cloudfunctions.v1.FunctionIamPolicy("function-py-iam", { |
| 51 | + projectsId: project, |
| 52 | + locationsId: region, |
| 53 | + functionsId: functionName, // func.name returns the long `projects/foo/locations/bat/functions/buzz` name which doesn't suit here |
| 54 | + bindings: [ |
| 55 | + { |
| 56 | + members: ["allUsers"], |
| 57 | + role: "roles/cloudfunctions.invoker", |
| 58 | + }, |
| 59 | + ], |
| 60 | +}, { dependsOn: func}); |
| 61 | + |
| 62 | +export const functionUrl = func.httpsTrigger.url; |
0 commit comments