@@ -449,6 +449,45 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
449
449
})
450
450
}
451
451
452
+ func TestAccCloudFunctionsFunction_vpcConnectorEgressSettings(t *testing.T) {
453
+ t.Parallel()
454
+
455
+ funcResourceName := "google_cloudfunctions_function.function"
456
+ functionName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
457
+ bucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt(t))
458
+ networkName := fmt.Sprintf("tf-test-net-%d", acctest.RandInt(t))
459
+ vpcConnectorName := fmt.Sprintf("tf-test-conn-%s", acctest.RandString(t, 5))
460
+ zipFilePath := acctest.CreateZIPArchiveForCloudFunctionSource(t, testHTTPTriggerPath)
461
+ projectNumber := os.Getenv("GOOGLE_PROJECT_NUMBER")
462
+ defer os.Remove(zipFilePath) // clean up
463
+
464
+ acctest.VcrTest(t, resource.TestCase{
465
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
466
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
467
+ CheckDestroy: testAccCheckCloudFunctionsFunctionDestroyProducer(t),
468
+ Steps: []resource.TestStep{
469
+ {
470
+ Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName, "PRIVATE_RANGES_ONLY"),
471
+ },
472
+ {
473
+ ResourceName: funcResourceName,
474
+ ImportState: true,
475
+ ImportStateVerify: true,
476
+ ImportStateVerifyIgnore: []string{"build_environment_variables", "labels", "terraform_labels"},
477
+ },
478
+ {
479
+ Config: testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update", "ALL_TRAFFIC"),
480
+ },
481
+ {
482
+ ResourceName: funcResourceName,
483
+ ImportState: true,
484
+ ImportStateVerify: true,
485
+ ImportStateVerifyIgnore: []string{"build_environment_variables", "labels", "terraform_labels"},
486
+ },
487
+ },
488
+ })
489
+ }
490
+
452
491
func TestAccCloudFunctionsFunction_secretEnvVar(t *testing.T) {
453
492
t.Parallel()
454
493
@@ -707,7 +746,7 @@ resource "google_storage_bucket_object" "archive" {
707
746
708
747
resource "google_cloudfunctions_function" "function" {
709
748
name = "%s"
710
- runtime = "nodejs10 "
749
+ runtime = "nodejs20 "
711
750
description = "test function"
712
751
docker_registry = "ARTIFACT_REGISTRY"
713
752
available_memory_mb = 128
@@ -756,7 +795,7 @@ resource "google_cloudfunctions_function" "function" {
756
795
source_archive_object = google_storage_bucket_object.archive.name
757
796
trigger_http = true
758
797
https_trigger_security_level = "SECURE_ALWAYS"
759
- runtime = "nodejs10 "
798
+ runtime = "nodejs20 "
760
799
timeout = 91
761
800
entry_point = "helloGET"
762
801
ingress_settings = "ALLOW_ALL"
@@ -812,7 +851,7 @@ resource "google_cloudbuild_worker_pool" "pool" {
812
851
813
852
resource "google_cloudfunctions_function" "function" {
814
853
name = "%[3]s"
815
- runtime = "nodejs10 "
854
+ runtime = "nodejs20 "
816
855
description = "test function"
817
856
docker_registry = "ARTIFACT_REGISTRY"
818
857
available_memory_mb = 128
@@ -846,7 +885,7 @@ resource "google_pubsub_topic" "sub" {
846
885
847
886
resource "google_cloudfunctions_function" "function" {
848
887
name = "%s"
849
- runtime = "nodejs10 "
888
+ runtime = "nodejs20 "
850
889
available_memory_mb = 128
851
890
source_archive_bucket = google_storage_bucket.bucket.name
852
891
source_archive_object = google_storage_bucket_object.archive.name
@@ -883,7 +922,7 @@ resource "google_storage_bucket_object" "archive" {
883
922
884
923
resource "google_cloudfunctions_function" "function" {
885
924
name = "%s"
886
- runtime = "nodejs10 "
925
+ runtime = "nodejs20 "
887
926
available_memory_mb = 128
888
927
source_archive_bucket = google_storage_bucket.bucket.name
889
928
source_archive_object = google_storage_bucket_object.archive.name
@@ -917,7 +956,7 @@ resource "google_storage_bucket_object" "archive" {
917
956
918
957
resource "google_cloudfunctions_function" "function" {
919
958
name = "%s"
920
- runtime = "nodejs10 "
959
+ runtime = "nodejs20 "
921
960
available_memory_mb = 128
922
961
source_archive_bucket = google_storage_bucket.bucket.name
923
962
source_archive_object = google_storage_bucket_object.archive.name
@@ -948,7 +987,7 @@ resource "google_storage_bucket_object" "archive" {
948
987
949
988
resource "google_cloudfunctions_function" "function" {
950
989
name = "%s"
951
- runtime = "nodejs10 "
990
+ runtime = "nodejs20 "
952
991
available_memory_mb = 128
953
992
source_archive_bucket = google_storage_bucket.bucket.name
954
993
source_archive_object = google_storage_bucket_object.archive.name
@@ -966,7 +1005,7 @@ func testAccCloudFunctionsFunction_sourceRepo(functionName, project string) stri
966
1005
return fmt.Sprintf(`
967
1006
resource "google_cloudfunctions_function" "function" {
968
1007
name = "%s"
969
- runtime = "nodejs10 "
1008
+ runtime = "nodejs20 "
970
1009
971
1010
source_repository {
972
1011
// There isn't yet an API that'll allow us to create a source repository and
@@ -1001,7 +1040,7 @@ data "google_compute_default_service_account" "default" {
1001
1040
1002
1041
resource "google_cloudfunctions_function" "function" {
1003
1042
name = "%s"
1004
- runtime = "nodejs10 "
1043
+ runtime = "nodejs20 "
1005
1044
1006
1045
source_archive_bucket = google_storage_bucket.bucket.name
1007
1046
source_archive_object = google_storage_bucket_object.archive.name
@@ -1052,7 +1091,7 @@ resource "google_storage_bucket_object" "archive" {
1052
1091
1053
1092
resource "google_cloudfunctions_function" "function" {
1054
1093
name = "%s"
1055
- runtime = "nodejs10 "
1094
+ runtime = "nodejs20 "
1056
1095
1057
1096
description = "test function"
1058
1097
available_memory_mb = 128
@@ -1077,6 +1116,70 @@ resource "google_cloudfunctions_function" "function" {
1077
1116
`, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
1078
1117
}
1079
1118
1119
+
1120
+ func testAccCloudFunctionsFunction_vpcConnectorEgressSettings(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName, vpcConnectorEgressSettings string) string {
1121
+ return fmt.Sprintf(`
1122
+ data "google_project" "project" {}
1123
+
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
+ resource "google_compute_network" "vpc" {
1131
+ name = "%s"
1132
+ auto_create_subnetworks = false
1133
+ }
1134
+
1135
+ resource "google_vpc_access_connector" "%s" {
1136
+ name = "%s"
1137
+ region = "us-central1"
1138
+ ip_cidr_range = "%s"
1139
+ network = google_compute_network.vpc.name
1140
+ min_throughput = 200
1141
+ max_throughput = 300
1142
+ }
1143
+
1144
+ resource "google_storage_bucket" "bucket" {
1145
+ name = "%s"
1146
+ location = "US"
1147
+ uniform_bucket_level_access = true
1148
+ }
1149
+
1150
+ resource "google_storage_bucket_object" "archive" {
1151
+ name = "index.zip"
1152
+ bucket = google_storage_bucket.bucket.name
1153
+ source = "%s"
1154
+ }
1155
+
1156
+ resource "google_cloudfunctions_function" "function" {
1157
+ name = "%s"
1158
+ runtime = "nodejs20"
1159
+
1160
+ description = "test function"
1161
+ available_memory_mb = 128
1162
+ source_archive_bucket = google_storage_bucket.bucket.name
1163
+ source_archive_object = google_storage_bucket_object.archive.name
1164
+ trigger_http = true
1165
+ timeout = 61
1166
+ entry_point = "helloGET"
1167
+ labels = {
1168
+ my-label = "my-label-value"
1169
+ }
1170
+ environment_variables = {
1171
+ TEST_ENV_VARIABLE = "test-env-variable-value"
1172
+ }
1173
+ max_instances = 10
1174
+ min_instances = 3
1175
+ vpc_connector = google_vpc_access_connector.%s.self_link
1176
+ vpc_connector_egress_settings = "%s"
1177
+
1178
+ depends_on = [google_project_iam_member.gcfadmin]
1179
+ }
1180
+ `, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName, vpcConnectorEgressSettings)
1181
+ }
1182
+
1080
1183
{{ if ne $.TargetVersionName `ga` -}}
1081
1184
func testAccCloudFunctionsFunction_docker_repository(arRepoName, functionName, bucketName, zipFilePath string) string {
1082
1185
return fmt.Sprintf(`
@@ -1113,7 +1216,7 @@ resource "google_storage_bucket_object" "archive" {
1113
1216
resource "google_cloudfunctions_function" "function" {
1114
1217
name = "%s"
1115
1218
description = "Function deployed to customer-provided Artifact Registry"
1116
- runtime = "nodejs10 "
1219
+ runtime = "nodejs20 "
1117
1220
available_memory_mb = 128
1118
1221
source_archive_bucket = google_storage_bucket.bucket.name
1119
1222
source_archive_object = google_storage_bucket_object.archive.name
@@ -1196,7 +1299,7 @@ resource "google_storage_bucket_object" "archive" {
1196
1299
resource "google_cloudfunctions_function" "function" {
1197
1300
name = "%s"
1198
1301
description = "CMEK function"
1199
- runtime = "nodejs10 "
1302
+ runtime = "nodejs20 "
1200
1303
available_memory_mb = 128
1201
1304
source_archive_bucket = google_storage_bucket.bucket.name
1202
1305
source_archive_object = google_storage_bucket_object.archive.name
@@ -1395,7 +1498,7 @@ resource "time_sleep" "wait_iam_roles_%[3]s" {
1395
1498
resource "google_cloudfunctions_function" "function" {
1396
1499
depends_on = [time_sleep.wait_iam_roles_%[3]s]
1397
1500
name = "%[5]s"
1398
- runtime = "nodejs10 "
1501
+ runtime = "nodejs20 "
1399
1502
1400
1503
source_archive_bucket = google_storage_bucket.bucket.name
1401
1504
source_archive_object = google_storage_bucket_object.archive.name
0 commit comments