Skip to content

Commit 627cc9a

Browse files
niffletsniharika-98
authored andcommitted
Fix bug with updating cloudfunctions vpcConnectorEgressSettings (GoogleCloudPlatform#12145)
1 parent 5680c9d commit 627cc9a

File tree

2 files changed

+117
-14
lines changed

2 files changed

+117
-14
lines changed

mmv1/third_party/terraform/services/cloudfunctions/resource_cloudfunctions_function.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
911911
updateMaskArr = append(updateMaskArr, "buildEnvironmentVariables")
912912
}
913913

914-
if d.HasChange("vpc_connector") {
914+
if d.HasChange("vpc_connector") || d.HasChange("vpc_connector_egress_settings") {
915915
function.VpcConnector = d.Get("vpc_connector").(string)
916916
updateMaskArr = append(updateMaskArr, "vpcConnector")
917917
}

mmv1/third_party/terraform/services/cloudfunctions/resource_cloudfunctions_function_test.go.tmpl

+116-13
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,45 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
449449
})
450450
}
451451

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+
452491
func TestAccCloudFunctionsFunction_secretEnvVar(t *testing.T) {
453492
t.Parallel()
454493

@@ -707,7 +746,7 @@ resource "google_storage_bucket_object" "archive" {
707746

708747
resource "google_cloudfunctions_function" "function" {
709748
name = "%s"
710-
runtime = "nodejs10"
749+
runtime = "nodejs20"
711750
description = "test function"
712751
docker_registry = "ARTIFACT_REGISTRY"
713752
available_memory_mb = 128
@@ -756,7 +795,7 @@ resource "google_cloudfunctions_function" "function" {
756795
source_archive_object = google_storage_bucket_object.archive.name
757796
trigger_http = true
758797
https_trigger_security_level = "SECURE_ALWAYS"
759-
runtime = "nodejs10"
798+
runtime = "nodejs20"
760799
timeout = 91
761800
entry_point = "helloGET"
762801
ingress_settings = "ALLOW_ALL"
@@ -812,7 +851,7 @@ resource "google_cloudbuild_worker_pool" "pool" {
812851

813852
resource "google_cloudfunctions_function" "function" {
814853
name = "%[3]s"
815-
runtime = "nodejs10"
854+
runtime = "nodejs20"
816855
description = "test function"
817856
docker_registry = "ARTIFACT_REGISTRY"
818857
available_memory_mb = 128
@@ -846,7 +885,7 @@ resource "google_pubsub_topic" "sub" {
846885

847886
resource "google_cloudfunctions_function" "function" {
848887
name = "%s"
849-
runtime = "nodejs10"
888+
runtime = "nodejs20"
850889
available_memory_mb = 128
851890
source_archive_bucket = google_storage_bucket.bucket.name
852891
source_archive_object = google_storage_bucket_object.archive.name
@@ -883,7 +922,7 @@ resource "google_storage_bucket_object" "archive" {
883922

884923
resource "google_cloudfunctions_function" "function" {
885924
name = "%s"
886-
runtime = "nodejs10"
925+
runtime = "nodejs20"
887926
available_memory_mb = 128
888927
source_archive_bucket = google_storage_bucket.bucket.name
889928
source_archive_object = google_storage_bucket_object.archive.name
@@ -917,7 +956,7 @@ resource "google_storage_bucket_object" "archive" {
917956

918957
resource "google_cloudfunctions_function" "function" {
919958
name = "%s"
920-
runtime = "nodejs10"
959+
runtime = "nodejs20"
921960
available_memory_mb = 128
922961
source_archive_bucket = google_storage_bucket.bucket.name
923962
source_archive_object = google_storage_bucket_object.archive.name
@@ -948,7 +987,7 @@ resource "google_storage_bucket_object" "archive" {
948987

949988
resource "google_cloudfunctions_function" "function" {
950989
name = "%s"
951-
runtime = "nodejs10"
990+
runtime = "nodejs20"
952991
available_memory_mb = 128
953992
source_archive_bucket = google_storage_bucket.bucket.name
954993
source_archive_object = google_storage_bucket_object.archive.name
@@ -966,7 +1005,7 @@ func testAccCloudFunctionsFunction_sourceRepo(functionName, project string) stri
9661005
return fmt.Sprintf(`
9671006
resource "google_cloudfunctions_function" "function" {
9681007
name = "%s"
969-
runtime = "nodejs10"
1008+
runtime = "nodejs20"
9701009

9711010
source_repository {
9721011
// 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" {
10011040

10021041
resource "google_cloudfunctions_function" "function" {
10031042
name = "%s"
1004-
runtime = "nodejs10"
1043+
runtime = "nodejs20"
10051044

10061045
source_archive_bucket = google_storage_bucket.bucket.name
10071046
source_archive_object = google_storage_bucket_object.archive.name
@@ -1052,7 +1091,7 @@ resource "google_storage_bucket_object" "archive" {
10521091

10531092
resource "google_cloudfunctions_function" "function" {
10541093
name = "%s"
1055-
runtime = "nodejs10"
1094+
runtime = "nodejs20"
10561095

10571096
description = "test function"
10581097
available_memory_mb = 128
@@ -1077,6 +1116,70 @@ resource "google_cloudfunctions_function" "function" {
10771116
`, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
10781117
}
10791118

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+
10801183
{{ if ne $.TargetVersionName `ga` -}}
10811184
func testAccCloudFunctionsFunction_docker_repository(arRepoName, functionName, bucketName, zipFilePath string) string {
10821185
return fmt.Sprintf(`
@@ -1113,7 +1216,7 @@ resource "google_storage_bucket_object" "archive" {
11131216
resource "google_cloudfunctions_function" "function" {
11141217
name = "%s"
11151218
description = "Function deployed to customer-provided Artifact Registry"
1116-
runtime = "nodejs10"
1219+
runtime = "nodejs20"
11171220
available_memory_mb = 128
11181221
source_archive_bucket = google_storage_bucket.bucket.name
11191222
source_archive_object = google_storage_bucket_object.archive.name
@@ -1196,7 +1299,7 @@ resource "google_storage_bucket_object" "archive" {
11961299
resource "google_cloudfunctions_function" "function" {
11971300
name = "%s"
11981301
description = "CMEK function"
1199-
runtime = "nodejs10"
1302+
runtime = "nodejs20"
12001303
available_memory_mb = 128
12011304
source_archive_bucket = google_storage_bucket.bucket.name
12021305
source_archive_object = google_storage_bucket_object.archive.name
@@ -1395,7 +1498,7 @@ resource "time_sleep" "wait_iam_roles_%[3]s" {
13951498
resource "google_cloudfunctions_function" "function" {
13961499
depends_on = [time_sleep.wait_iam_roles_%[3]s]
13971500
name = "%[5]s"
1398-
runtime = "nodejs10"
1501+
runtime = "nodejs20"
13991502

14001503
source_archive_bucket = google_storage_bucket.bucket.name
14011504
source_archive_object = google_storage_bucket_object.archive.name

0 commit comments

Comments
 (0)