Skip to content

Commit ff576ca

Browse files
Fix bug with updating cloudfunctions vpcConnectorEgressSettings (#12145) (#20437)
[upstream:b1ab6c65474d13c631f7a4b8755e82c82bbbc60c] Signed-off-by: Modular Magician <[email protected]>
1 parent 5c0aafd commit ff576ca

File tree

3 files changed

+117
-12
lines changed

3 files changed

+117
-12
lines changed

.changelog/12145.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
cloudfunctions: Fixed issue when updating `vpc_connector_egress_settings` field for `google_cloudfunctions_function` resource.
3+
```

google/services/cloudfunctions/resource_cloudfunctions_function.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
913913
updateMaskArr = append(updateMaskArr, "buildEnvironmentVariables")
914914
}
915915

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

google/services/cloudfunctions/resource_cloudfunctions_function_test.go

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,45 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
390390
})
391391
}
392392

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+
393432
func TestAccCloudFunctionsFunction_secretEnvVar(t *testing.T) {
394433
t.Parallel()
395434

@@ -648,7 +687,7 @@ resource "google_storage_bucket_object" "archive" {
648687
649688
resource "google_cloudfunctions_function" "function" {
650689
name = "%s"
651-
runtime = "nodejs10"
690+
runtime = "nodejs20"
652691
description = "test function"
653692
docker_registry = "ARTIFACT_REGISTRY"
654693
available_memory_mb = 128
@@ -697,7 +736,7 @@ resource "google_cloudfunctions_function" "function" {
697736
source_archive_object = google_storage_bucket_object.archive.name
698737
trigger_http = true
699738
https_trigger_security_level = "SECURE_ALWAYS"
700-
runtime = "nodejs10"
739+
runtime = "nodejs20"
701740
timeout = 91
702741
entry_point = "helloGET"
703742
ingress_settings = "ALLOW_ALL"
@@ -753,7 +792,7 @@ resource "google_cloudbuild_worker_pool" "pool" {
753792
754793
resource "google_cloudfunctions_function" "function" {
755794
name = "%[3]s"
756-
runtime = "nodejs10"
795+
runtime = "nodejs20"
757796
description = "test function"
758797
docker_registry = "ARTIFACT_REGISTRY"
759798
available_memory_mb = 128
@@ -787,7 +826,7 @@ resource "google_pubsub_topic" "sub" {
787826
788827
resource "google_cloudfunctions_function" "function" {
789828
name = "%s"
790-
runtime = "nodejs10"
829+
runtime = "nodejs20"
791830
available_memory_mb = 128
792831
source_archive_bucket = google_storage_bucket.bucket.name
793832
source_archive_object = google_storage_bucket_object.archive.name
@@ -824,7 +863,7 @@ resource "google_storage_bucket_object" "archive" {
824863
825864
resource "google_cloudfunctions_function" "function" {
826865
name = "%s"
827-
runtime = "nodejs10"
866+
runtime = "nodejs20"
828867
available_memory_mb = 128
829868
source_archive_bucket = google_storage_bucket.bucket.name
830869
source_archive_object = google_storage_bucket_object.archive.name
@@ -858,7 +897,7 @@ resource "google_storage_bucket_object" "archive" {
858897
859898
resource "google_cloudfunctions_function" "function" {
860899
name = "%s"
861-
runtime = "nodejs10"
900+
runtime = "nodejs20"
862901
available_memory_mb = 128
863902
source_archive_bucket = google_storage_bucket.bucket.name
864903
source_archive_object = google_storage_bucket_object.archive.name
@@ -889,7 +928,7 @@ resource "google_storage_bucket_object" "archive" {
889928
890929
resource "google_cloudfunctions_function" "function" {
891930
name = "%s"
892-
runtime = "nodejs10"
931+
runtime = "nodejs20"
893932
available_memory_mb = 128
894933
source_archive_bucket = google_storage_bucket.bucket.name
895934
source_archive_object = google_storage_bucket_object.archive.name
@@ -907,7 +946,7 @@ func testAccCloudFunctionsFunction_sourceRepo(functionName, project string) stri
907946
return fmt.Sprintf(`
908947
resource "google_cloudfunctions_function" "function" {
909948
name = "%s"
910-
runtime = "nodejs10"
949+
runtime = "nodejs20"
911950
912951
source_repository {
913952
// 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" {
942981
943982
resource "google_cloudfunctions_function" "function" {
944983
name = "%s"
945-
runtime = "nodejs10"
984+
runtime = "nodejs20"
946985
947986
source_archive_bucket = google_storage_bucket.bucket.name
948987
source_archive_object = google_storage_bucket_object.archive.name
@@ -993,7 +1032,7 @@ resource "google_storage_bucket_object" "archive" {
9931032
9941033
resource "google_cloudfunctions_function" "function" {
9951034
name = "%s"
996-
runtime = "nodejs10"
1035+
runtime = "nodejs20"
9971036
9981037
description = "test function"
9991038
available_memory_mb = 128
@@ -1018,6 +1057,69 @@ resource "google_cloudfunctions_function" "function" {
10181057
`, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
10191058
}
10201059

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+
10211123
func testAccCloudFunctionsFunction_secretEnvVar(secretName, versionName, bucketName, functionName, versionNumber, zipFilePath, accountId string) string {
10221124
return fmt.Sprintf(`
10231125
data "google_project" "project" {}
@@ -1203,7 +1305,7 @@ resource "time_sleep" "wait_iam_roles_%[3]s" {
12031305
resource "google_cloudfunctions_function" "function" {
12041306
depends_on = [time_sleep.wait_iam_roles_%[3]s]
12051307
name = "%[5]s"
1206-
runtime = "nodejs10"
1308+
runtime = "nodejs20"
12071309
12081310
source_archive_bucket = google_storage_bucket.bucket.name
12091311
source_archive_object = google_storage_bucket_object.archive.name

0 commit comments

Comments
 (0)