@@ -390,6 +390,45 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
390
390
})
391
391
}
392
392
393
+ func TestAccCloudFunctionsFunction_vpcConnectorEgressSettings (t * testing.T ) {
394
+ t .Parallel ()
395
+
396
+ funcResourceName := "google_cloudfunctions_function.function"
397
+ functionName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
398
+ bucketName := fmt .Sprintf ("tf-test-bucket-%d" , acctest .RandInt (t ))
399
+ networkName := fmt .Sprintf ("tf-test-net-%d" , acctest .RandInt (t ))
400
+ vpcConnectorName := fmt .Sprintf ("tf-test-conn-%s" , acctest .RandString (t , 5 ))
401
+ zipFilePath := acctest .CreateZIPArchiveForCloudFunctionSource (t , testHTTPTriggerPath )
402
+ projectNumber := os .Getenv ("GOOGLE_PROJECT_NUMBER" )
403
+ defer os .Remove (zipFilePath ) // clean up
404
+
405
+ acctest .VcrTest (t , resource.TestCase {
406
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
407
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
408
+ CheckDestroy : testAccCheckCloudFunctionsFunctionDestroyProducer (t ),
409
+ Steps : []resource.TestStep {
410
+ {
411
+ Config : testAccCloudFunctionsFunction_vpcConnectorEgressSettings (projectNumber , networkName , functionName , bucketName , zipFilePath , "10.10.0.0/28" , vpcConnectorName , "PRIVATE_RANGES_ONLY" ),
412
+ },
413
+ {
414
+ ResourceName : funcResourceName ,
415
+ ImportState : true ,
416
+ ImportStateVerify : true ,
417
+ ImportStateVerifyIgnore : []string {"build_environment_variables" , "labels" , "terraform_labels" },
418
+ },
419
+ {
420
+ Config : testAccCloudFunctionsFunction_vpcConnectorEgressSettings (projectNumber , networkName , functionName , bucketName , zipFilePath , "10.20.0.0/28" , vpcConnectorName + "-update" , "ALL_TRAFFIC" ),
421
+ },
422
+ {
423
+ ResourceName : funcResourceName ,
424
+ ImportState : true ,
425
+ ImportStateVerify : true ,
426
+ ImportStateVerifyIgnore : []string {"build_environment_variables" , "labels" , "terraform_labels" },
427
+ },
428
+ },
429
+ })
430
+ }
431
+
393
432
func TestAccCloudFunctionsFunction_secretEnvVar (t * testing.T ) {
394
433
t .Parallel ()
395
434
@@ -648,7 +687,7 @@ resource "google_storage_bucket_object" "archive" {
648
687
649
688
resource "google_cloudfunctions_function" "function" {
650
689
name = "%s"
651
- runtime = "nodejs10 "
690
+ runtime = "nodejs20 "
652
691
description = "test function"
653
692
docker_registry = "ARTIFACT_REGISTRY"
654
693
available_memory_mb = 128
@@ -697,7 +736,7 @@ resource "google_cloudfunctions_function" "function" {
697
736
source_archive_object = google_storage_bucket_object.archive.name
698
737
trigger_http = true
699
738
https_trigger_security_level = "SECURE_ALWAYS"
700
- runtime = "nodejs10 "
739
+ runtime = "nodejs20 "
701
740
timeout = 91
702
741
entry_point = "helloGET"
703
742
ingress_settings = "ALLOW_ALL"
@@ -753,7 +792,7 @@ resource "google_cloudbuild_worker_pool" "pool" {
753
792
754
793
resource "google_cloudfunctions_function" "function" {
755
794
name = "%[3]s"
756
- runtime = "nodejs10 "
795
+ runtime = "nodejs20 "
757
796
description = "test function"
758
797
docker_registry = "ARTIFACT_REGISTRY"
759
798
available_memory_mb = 128
@@ -787,7 +826,7 @@ resource "google_pubsub_topic" "sub" {
787
826
788
827
resource "google_cloudfunctions_function" "function" {
789
828
name = "%s"
790
- runtime = "nodejs10 "
829
+ runtime = "nodejs20 "
791
830
available_memory_mb = 128
792
831
source_archive_bucket = google_storage_bucket.bucket.name
793
832
source_archive_object = google_storage_bucket_object.archive.name
@@ -824,7 +863,7 @@ resource "google_storage_bucket_object" "archive" {
824
863
825
864
resource "google_cloudfunctions_function" "function" {
826
865
name = "%s"
827
- runtime = "nodejs10 "
866
+ runtime = "nodejs20 "
828
867
available_memory_mb = 128
829
868
source_archive_bucket = google_storage_bucket.bucket.name
830
869
source_archive_object = google_storage_bucket_object.archive.name
@@ -858,7 +897,7 @@ resource "google_storage_bucket_object" "archive" {
858
897
859
898
resource "google_cloudfunctions_function" "function" {
860
899
name = "%s"
861
- runtime = "nodejs10 "
900
+ runtime = "nodejs20 "
862
901
available_memory_mb = 128
863
902
source_archive_bucket = google_storage_bucket.bucket.name
864
903
source_archive_object = google_storage_bucket_object.archive.name
@@ -889,7 +928,7 @@ resource "google_storage_bucket_object" "archive" {
889
928
890
929
resource "google_cloudfunctions_function" "function" {
891
930
name = "%s"
892
- runtime = "nodejs10 "
931
+ runtime = "nodejs20 "
893
932
available_memory_mb = 128
894
933
source_archive_bucket = google_storage_bucket.bucket.name
895
934
source_archive_object = google_storage_bucket_object.archive.name
@@ -907,7 +946,7 @@ func testAccCloudFunctionsFunction_sourceRepo(functionName, project string) stri
907
946
return fmt .Sprintf (`
908
947
resource "google_cloudfunctions_function" "function" {
909
948
name = "%s"
910
- runtime = "nodejs10 "
949
+ runtime = "nodejs20 "
911
950
912
951
source_repository {
913
952
// There isn't yet an API that'll allow us to create a source repository and
@@ -942,7 +981,7 @@ data "google_compute_default_service_account" "default" {
942
981
943
982
resource "google_cloudfunctions_function" "function" {
944
983
name = "%s"
945
- runtime = "nodejs10 "
984
+ runtime = "nodejs20 "
946
985
947
986
source_archive_bucket = google_storage_bucket.bucket.name
948
987
source_archive_object = google_storage_bucket_object.archive.name
@@ -993,7 +1032,7 @@ resource "google_storage_bucket_object" "archive" {
993
1032
994
1033
resource "google_cloudfunctions_function" "function" {
995
1034
name = "%s"
996
- runtime = "nodejs10 "
1035
+ runtime = "nodejs20 "
997
1036
998
1037
description = "test function"
999
1038
available_memory_mb = 128
@@ -1018,6 +1057,69 @@ resource "google_cloudfunctions_function" "function" {
1018
1057
` , projectNumber , networkName , vpcConnectorName , vpcConnectorName , vpcIp , bucketName , zipFilePath , functionName , vpcConnectorName )
1019
1058
}
1020
1059
1060
+ func testAccCloudFunctionsFunction_vpcConnectorEgressSettings (projectNumber , networkName , functionName , bucketName , zipFilePath , vpcIp , vpcConnectorName , vpcConnectorEgressSettings string ) string {
1061
+ return fmt .Sprintf (`
1062
+ data "google_project" "project" {}
1063
+
1064
+ resource "google_project_iam_member" "gcfadmin" {
1065
+ project = data.google_project.project.project_id
1066
+ role = "roles/editor"
1067
+ member = "serviceAccount:service-%[email protected] "
1068
+ }
1069
+
1070
+ resource "google_compute_network" "vpc" {
1071
+ name = "%s"
1072
+ auto_create_subnetworks = false
1073
+ }
1074
+
1075
+ resource "google_vpc_access_connector" "%s" {
1076
+ name = "%s"
1077
+ region = "us-central1"
1078
+ ip_cidr_range = "%s"
1079
+ network = google_compute_network.vpc.name
1080
+ min_throughput = 200
1081
+ max_throughput = 300
1082
+ }
1083
+
1084
+ resource "google_storage_bucket" "bucket" {
1085
+ name = "%s"
1086
+ location = "US"
1087
+ uniform_bucket_level_access = true
1088
+ }
1089
+
1090
+ resource "google_storage_bucket_object" "archive" {
1091
+ name = "index.zip"
1092
+ bucket = google_storage_bucket.bucket.name
1093
+ source = "%s"
1094
+ }
1095
+
1096
+ resource "google_cloudfunctions_function" "function" {
1097
+ name = "%s"
1098
+ runtime = "nodejs20"
1099
+
1100
+ description = "test function"
1101
+ available_memory_mb = 128
1102
+ source_archive_bucket = google_storage_bucket.bucket.name
1103
+ source_archive_object = google_storage_bucket_object.archive.name
1104
+ trigger_http = true
1105
+ timeout = 61
1106
+ entry_point = "helloGET"
1107
+ labels = {
1108
+ my-label = "my-label-value"
1109
+ }
1110
+ environment_variables = {
1111
+ TEST_ENV_VARIABLE = "test-env-variable-value"
1112
+ }
1113
+ max_instances = 10
1114
+ min_instances = 3
1115
+ vpc_connector = google_vpc_access_connector.%s.self_link
1116
+ vpc_connector_egress_settings = "%s"
1117
+
1118
+ depends_on = [google_project_iam_member.gcfadmin]
1119
+ }
1120
+ ` , projectNumber , networkName , vpcConnectorName , vpcConnectorName , vpcIp , bucketName , zipFilePath , functionName , vpcConnectorName , vpcConnectorEgressSettings )
1121
+ }
1122
+
1021
1123
func testAccCloudFunctionsFunction_secretEnvVar (secretName , versionName , bucketName , functionName , versionNumber , zipFilePath , accountId string ) string {
1022
1124
return fmt .Sprintf (`
1023
1125
data "google_project" "project" {}
@@ -1203,7 +1305,7 @@ resource "time_sleep" "wait_iam_roles_%[3]s" {
1203
1305
resource "google_cloudfunctions_function" "function" {
1204
1306
depends_on = [time_sleep.wait_iam_roles_%[3]s]
1205
1307
name = "%[5]s"
1206
- runtime = "nodejs10 "
1308
+ runtime = "nodejs20 "
1207
1309
1208
1310
source_archive_bucket = google_storage_bucket.bucket.name
1209
1311
source_archive_object = google_storage_bucket_object.archive.name
0 commit comments