@@ -258,6 +258,35 @@ func TestAccCloudFunctionsFunction_sourceRepo(t *testing.T) {
258
258
})
259
259
}
260
260
261
+ func TestAccCloudFunctionsFunction_serviceAccountEmail (t * testing.T ) {
262
+ t .Parallel ()
263
+
264
+ funcResourceName := "google_cloudfunctions_function.function"
265
+ functionName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (10 ))
266
+ bucketName := fmt .Sprintf ("tf-test-bucket-%d" , acctest .RandInt ())
267
+ zipFilePath , err := createZIPArchiveForIndexJs (testHTTPTriggerPath )
268
+ if err != nil {
269
+ t .Fatal (err .Error ())
270
+ }
271
+ defer os .Remove (zipFilePath ) // clean up
272
+
273
+ resource .Test (t , resource.TestCase {
274
+ PreCheck : func () { testAccPreCheck (t ) },
275
+ Providers : testAccProviders ,
276
+ CheckDestroy : testAccCheckCloudFunctionsFunctionDestroy ,
277
+ Steps : []resource.TestStep {
278
+ {
279
+ Config : testAccCloudFunctionsFunction_serviceAccountEmail (functionName , bucketName , zipFilePath ),
280
+ },
281
+ {
282
+ ResourceName : funcResourceName ,
283
+ ImportState : true ,
284
+ ImportStateVerify : true ,
285
+ },
286
+ },
287
+ })
288
+ }
289
+
261
290
func testAccCheckCloudFunctionsFunctionDestroy (s * terraform.State ) error {
262
291
config := testAccProvider .Meta ().(* Config )
263
292
@@ -607,3 +636,30 @@ resource "google_cloudfunctions_function" "function" {
607
636
}
608
637
` , functionName , project )
609
638
}
639
+
640
+ func testAccCloudFunctionsFunction_serviceAccountEmail (functionName , bucketName , zipFilePath string ) string {
641
+ return fmt .Sprintf (`
642
+ resource "google_storage_bucket" "bucket" {
643
+ name = "%s"
644
+ }
645
+
646
+ resource "google_storage_bucket_object" "archive" {
647
+ name = "index.zip"
648
+ bucket = "${google_storage_bucket.bucket.name}"
649
+ source = "%s"
650
+ }
651
+
652
+ data "google_compute_default_service_account" "default" { }
653
+
654
+ resource "google_cloudfunctions_function" "function" {
655
+ name = "%s"
656
+
657
+ source_archive_bucket = "${google_storage_bucket.bucket.name}"
658
+ source_archive_object = "${google_storage_bucket_object.archive.name}"
659
+
660
+ service_account_email = "${data.google_compute_default_service_account.default.email}"
661
+
662
+ trigger_http = true
663
+ entry_point = "helloGET"
664
+ }` , bucketName , zipFilePath , functionName )
665
+ }
0 commit comments