Skip to content

Commit e036593

Browse files
modular-magicianemilymye
authored andcommitted
Add warning about private-by-default cloud functions (#4463)
Signed-off-by: Modular Magician <[email protected]>
1 parent ecda9f2 commit e036593

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

website/docs/r/cloudfunctions_function.html.markdown

+54-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ Creates a new Cloud Function. For more information see
1313
and
1414
[API](https://cloud.google.com/functions/docs/apis).
1515

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+
1622
## Example Usage
1723

24+
Secured function with a user allowed to invoke:
1825
```hcl
1926
resource "google_storage_bucket" "bucket" {
2027
name = "test-bucket"
@@ -40,13 +47,59 @@ resource "google_cloudfunctions_function" "function" {
4047
labels = {
4148
my-label = "my-label-value"
4249
}
43-
50+
4451
environment_variables = {
4552
MY_ENV_VAR = "my-env-var-value"
4653
}
4754
}
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+
member = "user:[email protected]"
64+
}
4865
```
4966

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+
```
50103
## Argument Reference
51104

52105
The following arguments are supported:

0 commit comments

Comments
 (0)