@@ -13,8 +13,15 @@ Creates a new Cloud Function. For more information see
13
13
and
14
14
[ API] ( https://cloud.google.com/functions/docs/apis ) .
15
15
16
+ ~ > ** Warning:** As of November 1, 2019, newly created Functions are
17
+ private-by-default and will require [ appropriate IAM permissions] ( https://cloud.google.com/functions/docs/reference/iam/roles )
18
+ to be invoked. See below examples for how to set up the appropriate permissions,
19
+ or view the [ Cloud Functions IAM resources] ( /docs/r/cloudfunctions_cloud_function_iam.html )
20
+ for Cloud Functions.
21
+
16
22
## Example Usage
17
23
24
+ Secured function with a user allowed to invoke:
18
25
``` hcl
19
26
resource "google_storage_bucket" "bucket" {
20
27
name = "test-bucket"
@@ -40,13 +47,59 @@ resource "google_cloudfunctions_function" "function" {
40
47
labels = {
41
48
my-label = "my-label-value"
42
49
}
43
-
50
+
44
51
environment_variables = {
45
52
MY_ENV_VAR = "my-env-var-value"
46
53
}
47
54
}
55
+
56
+ # Add IAM member for a user who can invoke the function (no admin actions)
57
+ resource "google_cloudfunctions_function_iam_member" "invoker" {
58
+ project = "${google_cloudfunctions_function.function.project}"
59
+ region = "${google_cloudfunctions_function.function.region}"
60
+ cloud_function = "${google_cloudfunctions_function.function.name}"
61
+
62
+ role = "roles/cloudfunctions.invoker"
63
+
64
+ }
48
65
```
49
66
67
+ A publically invocable function (similar behavior to functions created before
68
+ private-by-default):
69
+
70
+ ``` hcl
71
+ resource "google_storage_bucket" "bucket" {
72
+ name = "test-bucket"
73
+ }
74
+
75
+ resource "google_storage_bucket_object" "archive" {
76
+ name = "index.zip"
77
+ bucket = "${google_storage_bucket.bucket.name}"
78
+ source = "./path/to/zip/file/which/contains/code"
79
+ }
80
+
81
+ resource "google_cloudfunctions_function" "function" {
82
+ name = "function-test"
83
+ description = "My function"
84
+ runtime = "nodejs10"
85
+
86
+ available_memory_mb = 128
87
+ source_archive_bucket = "${google_storage_bucket.bucket.name}"
88
+ source_archive_object = "${google_storage_bucket_object.archive.name}"
89
+ trigger_http = true
90
+ entry_point = "helloGET"
91
+ }
92
+
93
+ # Add IAM member for a user who can invoke the function (no admin actions)
94
+ resource "google_cloudfunctions_function_iam_member" "invoker" {
95
+ project = "${google_cloudfunctions_function.function.project}"
96
+ region = "${google_cloudfunctions_function.function.region}"
97
+ cloud_function = "${google_cloudfunctions_function.function.name}"
98
+
99
+ role = "roles/cloudfunctions.invoker"
100
+ member = "allUsers"
101
+ }
102
+ ```
50
103
## Argument Reference
51
104
52
105
The following arguments are supported:
0 commit comments