Skip to content

Commit 6915c3f

Browse files
fix(functions) Add region tags to Cloud Functions samples (#6191) (#4438)
* Add region tags to Cloud Functions samples * add back provider * use pubsub function for test * Update cloudfunctions2_full.tf.erb * update test variables * update SA name * address review comments from #6170 replaces #6170 Co-authored-by: averikitsch <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: averikitsch <[email protected]>
1 parent b83130b commit 6915c3f

File tree

5 files changed

+53
-32
lines changed

5 files changed

+53
-32
lines changed

.changelog/6191.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/iam_cloudfunctions2_function_generated_test.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ func TestAccCloudfunctions2functionIamPolicyGenerated(t *testing.T) {
9696

9797
func testAccCloudfunctions2functionIamMember_basicGenerated(context map[string]interface{}) string {
9898
return Nprintf(`
99+
# [START functions_v2_basic]
99100
resource "google_storage_bucket" "bucket" {
100101
provider = google-beta
101-
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
102+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" # Every bucket name must be globally unique
102103
location = "US"
103104
uniform_bucket_level_access = true
104105
}
@@ -107,7 +108,7 @@ resource "google_storage_bucket_object" "object" {
107108
provider = google-beta
108109
name = "function-source.zip"
109110
bucket = google_storage_bucket.bucket.name
110-
source = "%{zip_path}"
111+
source = "%{zip_path}" # Add path to the zipped function source code
111112
}
112113
113114
resource "google_cloudfunctions2_function" "terraform-test2" {
@@ -118,7 +119,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
118119
119120
build_config {
120121
runtime = "nodejs16"
121-
entry_point = "helloHttp"
122+
entry_point = "helloHttp" # Set the entry point
122123
source {
123124
storage_source {
124125
bucket = google_storage_bucket.bucket.name
@@ -133,6 +134,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
133134
timeout_seconds = 60
134135
}
135136
}
137+
# [END functions_v2_basic]
136138
137139
resource "google_cloudfunctions2_function_iam_member" "foo" {
138140
provider = google-beta
@@ -146,9 +148,10 @@ resource "google_cloudfunctions2_function_iam_member" "foo" {
146148

147149
func testAccCloudfunctions2functionIamPolicy_basicGenerated(context map[string]interface{}) string {
148150
return Nprintf(`
151+
# [START functions_v2_basic]
149152
resource "google_storage_bucket" "bucket" {
150153
provider = google-beta
151-
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
154+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" # Every bucket name must be globally unique
152155
location = "US"
153156
uniform_bucket_level_access = true
154157
}
@@ -157,7 +160,7 @@ resource "google_storage_bucket_object" "object" {
157160
provider = google-beta
158161
name = "function-source.zip"
159162
bucket = google_storage_bucket.bucket.name
160-
source = "%{zip_path}"
163+
source = "%{zip_path}" # Add path to the zipped function source code
161164
}
162165
163166
resource "google_cloudfunctions2_function" "terraform-test2" {
@@ -168,7 +171,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
168171
169172
build_config {
170173
runtime = "nodejs16"
171-
entry_point = "helloHttp"
174+
entry_point = "helloHttp" # Set the entry point
172175
source {
173176
storage_source {
174177
bucket = google_storage_bucket.bucket.name
@@ -183,6 +186,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
183186
timeout_seconds = 60
184187
}
185188
}
189+
# [END functions_v2_basic]
186190
187191
data "google_iam_policy" "foo" {
188192
provider = google-beta
@@ -203,9 +207,10 @@ resource "google_cloudfunctions2_function_iam_policy" "foo" {
203207

204208
func testAccCloudfunctions2functionIamPolicy_emptyBinding(context map[string]interface{}) string {
205209
return Nprintf(`
210+
# [START functions_v2_basic]
206211
resource "google_storage_bucket" "bucket" {
207212
provider = google-beta
208-
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
213+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" # Every bucket name must be globally unique
209214
location = "US"
210215
uniform_bucket_level_access = true
211216
}
@@ -214,7 +219,7 @@ resource "google_storage_bucket_object" "object" {
214219
provider = google-beta
215220
name = "function-source.zip"
216221
bucket = google_storage_bucket.bucket.name
217-
source = "%{zip_path}"
222+
source = "%{zip_path}" # Add path to the zipped function source code
218223
}
219224
220225
resource "google_cloudfunctions2_function" "terraform-test2" {
@@ -225,7 +230,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
225230
226231
build_config {
227232
runtime = "nodejs16"
228-
entry_point = "helloHttp"
233+
entry_point = "helloHttp" # Set the entry point
229234
source {
230235
storage_source {
231236
bucket = google_storage_bucket.bucket.name
@@ -240,6 +245,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
240245
timeout_seconds = 60
241246
}
242247
}
248+
# [END functions_v2_basic]
243249
244250
data "google_iam_policy" "foo" {
245251
provider = google-beta
@@ -256,9 +262,10 @@ resource "google_cloudfunctions2_function_iam_policy" "foo" {
256262

257263
func testAccCloudfunctions2functionIamBinding_basicGenerated(context map[string]interface{}) string {
258264
return Nprintf(`
265+
# [START functions_v2_basic]
259266
resource "google_storage_bucket" "bucket" {
260267
provider = google-beta
261-
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
268+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" # Every bucket name must be globally unique
262269
location = "US"
263270
uniform_bucket_level_access = true
264271
}
@@ -267,7 +274,7 @@ resource "google_storage_bucket_object" "object" {
267274
provider = google-beta
268275
name = "function-source.zip"
269276
bucket = google_storage_bucket.bucket.name
270-
source = "%{zip_path}"
277+
source = "%{zip_path}" # Add path to the zipped function source code
271278
}
272279
273280
resource "google_cloudfunctions2_function" "terraform-test2" {
@@ -278,7 +285,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
278285
279286
build_config {
280287
runtime = "nodejs16"
281-
entry_point = "helloHttp"
288+
entry_point = "helloHttp" # Set the entry point
282289
source {
283290
storage_source {
284291
bucket = google_storage_bucket.bucket.name
@@ -293,6 +300,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
293300
timeout_seconds = 60
294301
}
295302
}
303+
# [END functions_v2_basic]
296304
297305
resource "google_cloudfunctions2_function_iam_binding" "foo" {
298306
provider = google-beta
@@ -306,9 +314,10 @@ resource "google_cloudfunctions2_function_iam_binding" "foo" {
306314

307315
func testAccCloudfunctions2functionIamBinding_updateGenerated(context map[string]interface{}) string {
308316
return Nprintf(`
317+
# [START functions_v2_basic]
309318
resource "google_storage_bucket" "bucket" {
310319
provider = google-beta
311-
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
320+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" # Every bucket name must be globally unique
312321
location = "US"
313322
uniform_bucket_level_access = true
314323
}
@@ -317,7 +326,7 @@ resource "google_storage_bucket_object" "object" {
317326
provider = google-beta
318327
name = "function-source.zip"
319328
bucket = google_storage_bucket.bucket.name
320-
source = "%{zip_path}"
329+
source = "%{zip_path}" # Add path to the zipped function source code
321330
}
322331
323332
resource "google_cloudfunctions2_function" "terraform-test2" {
@@ -328,7 +337,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
328337
329338
build_config {
330339
runtime = "nodejs16"
331-
entry_point = "helloHttp"
340+
entry_point = "helloHttp" # Set the entry point
332341
source {
333342
storage_source {
334343
bucket = google_storage_bucket.bucket.name
@@ -343,6 +352,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
343352
timeout_seconds = 60
344353
}
345354
}
355+
# [END functions_v2_basic]
346356
347357
resource "google_cloudfunctions2_function_iam_binding" "foo" {
348358
provider = google-beta

google-beta/resource_cloudfunctions2_function_generated_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ func TestAccCloudfunctions2function_cloudfunctions2BasicExample(t *testing.T) {
5353

5454
func testAccCloudfunctions2function_cloudfunctions2BasicExample(context map[string]interface{}) string {
5555
return Nprintf(`
56+
# [START functions_v2_basic]
5657
resource "google_storage_bucket" "bucket" {
5758
provider = google-beta
58-
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
59+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" # Every bucket name must be globally unique
5960
location = "US"
6061
uniform_bucket_level_access = true
6162
}
@@ -64,7 +65,7 @@ resource "google_storage_bucket_object" "object" {
6465
provider = google-beta
6566
name = "function-source.zip"
6667
bucket = google_storage_bucket.bucket.name
67-
source = "%{zip_path}"
68+
source = "%{zip_path}" # Add path to the zipped function source code
6869
}
6970
7071
resource "google_cloudfunctions2_function" "terraform-test2" {
@@ -75,7 +76,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
7576
7677
build_config {
7778
runtime = "nodejs16"
78-
entry_point = "helloHttp"
79+
entry_point = "helloHttp" # Set the entry point
7980
source {
8081
storage_source {
8182
bucket = google_storage_bucket.bucket.name
@@ -90,14 +91,15 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
9091
timeout_seconds = 60
9192
}
9293
}
94+
# [END functions_v2_basic]
9395
`, context)
9496
}
9597

9698
func TestAccCloudfunctions2function_cloudfunctions2FullExample(t *testing.T) {
9799
t.Parallel()
98100

99101
context := map[string]interface{}{
100-
"zip_path": "./test-fixtures/cloudfunctions2/function-source.zip",
102+
"zip_path": "./test-fixtures/cloudfunctions2/function-source-pubsub.zip",
101103
"primary_resource_id": "terraform-test",
102104
"location": "us-central1",
103105
"random_suffix": randString(t, 10),
@@ -123,20 +125,21 @@ func TestAccCloudfunctions2function_cloudfunctions2FullExample(t *testing.T) {
123125

124126
func testAccCloudfunctions2function_cloudfunctions2FullExample(context map[string]interface{}) string {
125127
return Nprintf(`
128+
# [START functions_v2_full]
126129
resource "google_service_account" "account" {
127130
provider = google-beta
128-
account_id = "test-service-account"
131+
account_id = "tf-test-s-a%{random_suffix}"
129132
display_name = "Test Service Account"
130133
}
131134
132135
resource "google_pubsub_topic" "sub" {
133136
provider = google-beta
134-
name = "pubsub"
137+
name = "tf-test-pub-sub%{random_suffix}"
135138
}
136139
137140
resource "google_storage_bucket" "bucket" {
138141
provider = google-beta
139-
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
142+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" # Every bucket name must be globally unique
140143
location = "US"
141144
uniform_bucket_level_access = true
142145
}
@@ -145,7 +148,7 @@ resource "google_storage_bucket_object" "object" {
145148
provider = google-beta
146149
name = "function-source.zip"
147150
bucket = google_storage_bucket.bucket.name
148-
source = "%{zip_path}"
151+
source = "%{zip_path}" # Add path to the zipped function source code
149152
}
150153
151154
resource "google_cloudfunctions2_function" "terraform-test" {
@@ -156,7 +159,7 @@ resource "google_cloudfunctions2_function" "terraform-test" {
156159
157160
build_config {
158161
runtime = "nodejs16"
159-
entry_point = "helloHttp"
162+
entry_point = "helloPubSub" # Set the entry point
160163
environment_variables = {
161164
BUILD_CONFIG_TEST = "build_test"
162165
}
@@ -189,6 +192,7 @@ resource "google_cloudfunctions2_function" "terraform-test" {
189192
service_account_email = google_service_account.account.email
190193
}
191194
}
195+
# [END functions_v2_full]
192196
`, context)
193197
}
194198

Binary file not shown.

website/docs/r/cloudfunctions2_function.html.markdown

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ To get more information about function, see:
4040

4141

4242
```hcl
43+
# [START functions_v2_basic]
4344
resource "google_storage_bucket" "bucket" {
4445
provider = google-beta
45-
name = "cloudfunctions2-function-bucket"
46+
name = "cloudfunctions2-function-bucket" # Every bucket name must be globally unique
4647
location = "US"
4748
uniform_bucket_level_access = true
4849
}
@@ -51,7 +52,7 @@ resource "google_storage_bucket_object" "object" {
5152
provider = google-beta
5253
name = "function-source.zip"
5354
bucket = google_storage_bucket.bucket.name
54-
source = "path/to/index.zip"
55+
source = "path/to/index.zip" # Add path to the zipped function source code
5556
}
5657
5758
resource "google_cloudfunctions2_function" "terraform-test2" {
@@ -62,7 +63,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
6263
6364
build_config {
6465
runtime = "nodejs16"
65-
entry_point = "helloHttp"
66+
entry_point = "helloHttp" # Set the entry point
6667
source {
6768
storage_source {
6869
bucket = google_storage_bucket.bucket.name
@@ -77,6 +78,7 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
7778
timeout_seconds = 60
7879
}
7980
}
81+
# [END functions_v2_basic]
8082
```
8183
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
8284
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=cloudfunctions2_full&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
@@ -87,20 +89,21 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
8789

8890

8991
```hcl
92+
# [START functions_v2_full]
9093
resource "google_service_account" "account" {
9194
provider = google-beta
92-
account_id = "test-service-account"
95+
account_id = "s-a"
9396
display_name = "Test Service Account"
9497
}
9598
9699
resource "google_pubsub_topic" "sub" {
97100
provider = google-beta
98-
name = "pubsub"
101+
name = "pub-sub"
99102
}
100103
101104
resource "google_storage_bucket" "bucket" {
102105
provider = google-beta
103-
name = "cloudfunctions2-function-bucket"
106+
name = "cloudfunctions2-function-bucket" # Every bucket name must be globally unique
104107
location = "US"
105108
uniform_bucket_level_access = true
106109
}
@@ -109,7 +112,7 @@ resource "google_storage_bucket_object" "object" {
109112
provider = google-beta
110113
name = "function-source.zip"
111114
bucket = google_storage_bucket.bucket.name
112-
source = "path/to/index.zip"
115+
source = "path/to/index.zip" # Add path to the zipped function source code
113116
}
114117
115118
resource "google_cloudfunctions2_function" "terraform-test" {
@@ -120,7 +123,7 @@ resource "google_cloudfunctions2_function" "terraform-test" {
120123
121124
build_config {
122125
runtime = "nodejs16"
123-
entry_point = "helloHttp"
126+
entry_point = "helloPubSub" # Set the entry point
124127
environment_variables = {
125128
BUILD_CONFIG_TEST = "build_test"
126129
}
@@ -153,6 +156,7 @@ resource "google_cloudfunctions2_function" "terraform-test" {
153156
service_account_email = google_service_account.account.email
154157
}
155158
}
159+
# [END functions_v2_full]
156160
```
157161

158162
## Argument Reference

0 commit comments

Comments
 (0)