@@ -25,6 +25,19 @@ const testFirestoreTriggerPath = "./test-fixtures/firestore_trigger.js"
25
25
const testSecretEnvVarFunctionPath = "./test-fixtures/secret_environment_variables.js"
26
26
const testSecretVolumesMountFunctionPath = "./test-fixtures/secret_volumes_mount.js"
27
27
28
+ func bootstrapGcfAdminAgents(t *testing.T) {
29
+ acctest.BootstrapIamMembers(t, []acctest.IamMember{
30
+ {
31
+ Member: "serviceAccount:service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com",
32
+ Role: "roles/vpcaccess.admin",
33
+ },
34
+ {
35
+ Member: "serviceAccount:service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com",
36
+ Role: "roles/storage.objectViewer",
37
+ },
38
+ })
39
+ }
40
+
28
41
func TestAccCloudFunctionsFunction_basic(t *testing.T) {
29
42
t.Parallel()
30
43
@@ -419,16 +432,16 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
419
432
networkName := fmt.Sprintf("tf-test-net-%d", acctest.RandInt(t))
420
433
vpcConnectorName := fmt.Sprintf("tf-test-conn-%s", acctest.RandString(t, 5))
421
434
zipFilePath := acctest.CreateZIPArchiveForCloudFunctionSource(t, testHTTPTriggerPath)
422
- projectNumber := os.Getenv("GOOGLE_PROJECT_NUMBER")
423
435
defer os.Remove(zipFilePath) // clean up
424
436
437
+ bootstrapGcfAdminAgents(t)
425
438
acctest.VcrTest(t, resource.TestCase{
426
439
PreCheck: func() { acctest.AccTestPreCheck(t) },
427
440
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
428
441
CheckDestroy: testAccCheckCloudFunctionsFunctionDestroyProducer(t),
429
442
Steps: []resource.TestStep{
430
443
{
431
- Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName),
444
+ Config: testAccCloudFunctionsFunction_vpcConnector(networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName),
432
445
},
433
446
{
434
447
ResourceName: funcResourceName,
@@ -437,7 +450,7 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
437
450
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels", "terraform_labels"},
438
451
},
439
452
{
440
- Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update"),
453
+ Config: testAccCloudFunctionsFunction_vpcConnector(networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update"),
441
454
},
442
455
{
443
456
ResourceName: funcResourceName,
@@ -458,16 +471,16 @@ func TestAccCloudFunctionsFunction_vpcConnectorEgressSettings(t *testing.T) {
458
471
networkName := fmt.Sprintf("tf-test-net-%d", acctest.RandInt(t))
459
472
vpcConnectorName := fmt.Sprintf("tf-test-conn-%s", acctest.RandString(t, 5))
460
473
zipFilePath := acctest.CreateZIPArchiveForCloudFunctionSource(t, testHTTPTriggerPath)
461
- projectNumber := os.Getenv("GOOGLE_PROJECT_NUMBER")
462
474
defer os.Remove(zipFilePath) // clean up
463
475
476
+ bootstrapGcfAdminAgents(t)
464
477
acctest.VcrTest(t, resource.TestCase{
465
478
PreCheck: func() { acctest.AccTestPreCheck(t) },
466
479
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
467
480
CheckDestroy: testAccCheckCloudFunctionsFunctionDestroyProducer(t),
468
481
Steps: []resource.TestStep{
469
482
{
470
- Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName, "PRIVATE_RANGES_ONLY"),
483
+ Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName, "PRIVATE_RANGES_ONLY"),
471
484
},
472
485
{
473
486
ResourceName: funcResourceName,
@@ -476,7 +489,7 @@ func TestAccCloudFunctionsFunction_vpcConnectorEgressSettings(t *testing.T) {
476
489
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels", "terraform_labels"},
477
490
},
478
491
{
479
- Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update", "ALL_TRAFFIC"),
492
+ Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update", "ALL_TRAFFIC"),
480
493
},
481
494
{
482
495
ResourceName: funcResourceName,
@@ -1053,16 +1066,10 @@ resource "google_cloudfunctions_function" "function" {
1053
1066
`, bucketName, zipFilePath, functionName)
1054
1067
}
1055
1068
1056
- func testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName string) string {
1069
+ func testAccCloudFunctionsFunction_vpcConnector(networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName string) string {
1057
1070
return fmt.Sprintf(`
1058
1071
data "google_project" "project" {}
1059
1072
1060
- resource "google_project_iam_member" "gcfadmin" {
1061
- project = data.google_project.project.project_id
1062
- role = "roles/editor"
1063
- member = "serviceAccount:service-%
[email protected] "
1064
- }
1065
-
1066
1073
resource "google_compute_network" "vpc" {
1067
1074
name = "%s"
1068
1075
auto_create_subnetworks = false
@@ -1110,23 +1117,15 @@ resource "google_cloudfunctions_function" "function" {
1110
1117
min_instances = 3
1111
1118
vpc_connector = google_vpc_access_connector.%s.self_link
1112
1119
vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY"
1113
-
1114
- depends_on = [google_project_iam_member.gcfadmin]
1115
1120
}
1116
- `, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
1121
+ `, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
1117
1122
}
1118
1123
1119
1124
1120
- func testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName, vpcConnectorEgressSettings string) string {
1125
+ func testAccCloudFunctionsFunction_vpcConnectorEgressSettings(networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName, vpcConnectorEgressSettings string) string {
1121
1126
return fmt.Sprintf(`
1122
1127
data "google_project" "project" {}
1123
1128
1124
- resource "google_project_iam_member" "gcfadmin" {
1125
- project = data.google_project.project.project_id
1126
- role = "roles/editor"
1127
- member = "serviceAccount:service-%
[email protected] "
1128
- }
1129
-
1130
1129
resource "google_compute_network" "vpc" {
1131
1130
name = "%s"
1132
1131
auto_create_subnetworks = false
@@ -1174,10 +1173,8 @@ resource "google_cloudfunctions_function" "function" {
1174
1173
min_instances = 3
1175
1174
vpc_connector = google_vpc_access_connector.%s.self_link
1176
1175
vpc_connector_egress_settings = "%s"
1177
-
1178
- depends_on = [google_project_iam_member.gcfadmin]
1179
1176
}
1180
- `, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName, vpcConnectorEgressSettings)
1177
+ `, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName, vpcConnectorEgressSettings)
1181
1178
}
1182
1179
1183
1180
{{ if ne $.TargetVersionName `ga` -}}
0 commit comments