-
Notifications
You must be signed in to change notification settings - Fork 880
/
main.go
58 lines (51 loc) · 1.59 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/cloudfunctions"
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/storage"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create a bucket.
bucket, err := storage.NewBucket(ctx, "bucket", nil)
if err != nil {
return err
}
// Create an object in our bucket with our function.
bucketObjectArgs := &storage.BucketObjectArgs{
Bucket: bucket.Name,
Source: pulumi.NewFileArchive("gofunc"),
}
bucketObject, err := storage.NewBucketObject(ctx, "go-zip", bucketObjectArgs)
if err != nil {
return err
}
// Set arguments for creating the function resource.
args := &cloudfunctions.FunctionArgs{
SourceArchiveBucket: bucket.Name,
Runtime: pulumi.String("go120"),
SourceArchiveObject: bucketObject.Name,
EntryPoint: pulumi.String("Handler"),
TriggerHttp: pulumi.Bool(true),
AvailableMemoryMb: pulumi.Int(128),
}
// Create the function using the args.
function, err := cloudfunctions.NewFunction(ctx, "basicFunction", args)
if err != nil {
return err
}
_, err = cloudfunctions.NewFunctionIamMember(ctx, "invoker", &cloudfunctions.FunctionIamMemberArgs{
Project: function.Project,
Region: function.Region,
CloudFunction: function.Name,
Role: pulumi.String("roles/cloudfunctions.invoker"),
Member: pulumi.String("allUsers"),
})
if err != nil {
return err
}
// Export the trigger URL.
ctx.Export("function", function.HttpsTriggerUrl)
return nil
})
}