@@ -25,6 +25,15 @@ 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
+ }
36
+
28
37
func TestAccCloudFunctionsFunction_basic(t *testing.T) {
29
38
t.Parallel()
30
39
@@ -419,16 +428,16 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
419
428
networkName := fmt.Sprintf("tf-test-net-%d", acctest.RandInt(t))
420
429
vpcConnectorName := fmt.Sprintf("tf-test-conn-%s", acctest.RandString(t, 5))
421
430
zipFilePath := acctest.CreateZIPArchiveForCloudFunctionSource(t, testHTTPTriggerPath)
422
- projectNumber := os.Getenv("GOOGLE_PROJECT_NUMBER")
423
431
defer os.Remove(zipFilePath) // clean up
424
432
433
+ bootstrapGcfAdminAgents(t)
425
434
acctest.VcrTest(t, resource.TestCase{
426
435
PreCheck: func() { acctest.AccTestPreCheck(t) },
427
436
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
428
437
CheckDestroy: testAccCheckCloudFunctionsFunctionDestroyProducer(t),
429
438
Steps: []resource.TestStep{
430
439
{
431
- Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName),
440
+ Config: testAccCloudFunctionsFunction_vpcConnector(networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName),
432
441
},
433
442
{
434
443
ResourceName: funcResourceName,
@@ -437,7 +446,7 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
437
446
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels", "terraform_labels"},
438
447
},
439
448
{
440
- Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update"),
449
+ Config: testAccCloudFunctionsFunction_vpcConnector(networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update"),
441
450
},
442
451
{
443
452
ResourceName: funcResourceName,
@@ -458,16 +467,16 @@ func TestAccCloudFunctionsFunction_vpcConnectorEgressSettings(t *testing.T) {
458
467
networkName := fmt.Sprintf("tf-test-net-%d", acctest.RandInt(t))
459
468
vpcConnectorName := fmt.Sprintf("tf-test-conn-%s", acctest.RandString(t, 5))
460
469
zipFilePath := acctest.CreateZIPArchiveForCloudFunctionSource(t, testHTTPTriggerPath)
461
- projectNumber := os.Getenv("GOOGLE_PROJECT_NUMBER")
462
470
defer os.Remove(zipFilePath) // clean up
463
471
472
+ bootstrapGcfAdminAgents(t)
464
473
acctest.VcrTest(t, resource.TestCase{
465
474
PreCheck: func() { acctest.AccTestPreCheck(t) },
466
475
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
467
476
CheckDestroy: testAccCheckCloudFunctionsFunctionDestroyProducer(t),
468
477
Steps: []resource.TestStep{
469
478
{
470
- Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName, "PRIVATE_RANGES_ONLY"),
479
+ Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName, "PRIVATE_RANGES_ONLY"),
471
480
},
472
481
{
473
482
ResourceName: funcResourceName,
@@ -476,7 +485,7 @@ func TestAccCloudFunctionsFunction_vpcConnectorEgressSettings(t *testing.T) {
476
485
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels", "terraform_labels"},
477
486
},
478
487
{
479
- Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update", "ALL_TRAFFIC"),
488
+ Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update", "ALL_TRAFFIC"),
480
489
},
481
490
{
482
491
ResourceName: funcResourceName,
@@ -1053,16 +1062,10 @@ resource "google_cloudfunctions_function" "function" {
1053
1062
`, bucketName, zipFilePath, functionName)
1054
1063
}
1055
1064
1056
- func testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName string) string {
1065
+ func testAccCloudFunctionsFunction_vpcConnector(networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName string) string {
1057
1066
return fmt.Sprintf(`
1058
1067
data "google_project" "project" {}
1059
1068
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
1069
resource "google_compute_network" "vpc" {
1067
1070
name = "%s"
1068
1071
auto_create_subnetworks = false
@@ -1110,23 +1113,15 @@ resource "google_cloudfunctions_function" "function" {
1110
1113
min_instances = 3
1111
1114
vpc_connector = google_vpc_access_connector.%s.self_link
1112
1115
vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY"
1113
-
1114
- depends_on = [google_project_iam_member.gcfadmin]
1115
1116
}
1116
- `, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
1117
+ `, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
1117
1118
}
1118
1119
1119
1120
1120
- func testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName, vpcConnectorEgressSettings string) string {
1121
+ func testAccCloudFunctionsFunction_vpcConnectorEgressSettings(networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName, vpcConnectorEgressSettings string) string {
1121
1122
return fmt.Sprintf(`
1122
1123
data "google_project" "project" {}
1123
1124
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
1125
resource "google_compute_network" "vpc" {
1131
1126
name = "%s"
1132
1127
auto_create_subnetworks = false
@@ -1174,10 +1169,8 @@ resource "google_cloudfunctions_function" "function" {
1174
1169
min_instances = 3
1175
1170
vpc_connector = google_vpc_access_connector.%s.self_link
1176
1171
vpc_connector_egress_settings = "%s"
1177
-
1178
- depends_on = [google_project_iam_member.gcfadmin]
1179
1172
}
1180
- `, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName, vpcConnectorEgressSettings)
1173
+ `, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName, vpcConnectorEgressSettings)
1181
1174
}
1182
1175
1183
1176
{{ if ne $.TargetVersionName `ga` -}}
0 commit comments