Skip to content

Commit

Permalink
add vpc_connector to update (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 authored Mar 4, 2020
1 parent aac3bf2 commit f6b990a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
updateMaskArr = append(updateMaskArr, "environmentVariables")
}

if d.HasChange("vpc_connector") {
function.VpcConnector = d.Get("vpc_connector").(string)
updateMaskArr = append(updateMaskArr, "vpcConnector")
}

if d.HasChange("event_trigger") {
function.EventTrigger = expandEventTrigger(d.Get("event_trigger").([]interface{}), project)
updateMaskArr = append(updateMaskArr, "eventTrigger", "eventTrigger.failurePolicy.retry")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,11 @@ func TestAccCloudFunctionsFunction_serviceAccountEmail(t *testing.T) {
func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
t.Parallel()

funcResourceName := "google_cloudfunctions_function.function"
functionName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
bucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())
networkName := fmt.Sprintf("tf-test-net-%d", acctest.RandInt())
vpcConnectorName := fmt.Sprintf("tf-test-connector-%s", acctest.RandString(5))
vpcConnectorName := fmt.Sprintf("tf-test-conn-%s", acctest.RandString(5))
zipFilePath := createZIPArchiveForCloudFunctionSource(t, testHTTPTriggerPath)
projectNumber := os.Getenv("GOOGLE_PROJECT_NUMBER")
defer os.Remove(zipFilePath) // clean up
Expand All @@ -336,7 +337,20 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
CheckDestroy: testAccCheckCloudFunctionsFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcConnectorName),
Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.10.0.0/28", vpcConnectorName),
},
{
ResourceName: funcResourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update"),
},
{
ResourceName: funcResourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down Expand Up @@ -758,7 +772,7 @@ resource "google_cloudfunctions_function" "function" {
`, bucketName, zipFilePath, functionName)
}

func testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcConnectorName string) string {
func testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, vpcIp, vpcConnectorName string) string {
return fmt.Sprintf(`

resource "google_project_iam_member" "gcfadmin" {
Expand All @@ -771,10 +785,10 @@ resource "google_compute_network" "vpc" {
auto_create_subnetworks = false
}

resource "google_vpc_access_connector" "connector" {
resource "google_vpc_access_connector" "%s" {
name = "%s"
region = "us-central1"
ip_cidr_range = "10.10.0.0/28"
ip_cidr_range = "%s"
network = google_compute_network.vpc.name
}

Expand Down Expand Up @@ -806,9 +820,9 @@ resource "google_cloudfunctions_function" "function" {
TEST_ENV_VARIABLE = "test-env-variable-value"
}
max_instances = 10
vpc_connector = google_vpc_access_connector.connector.self_link
vpc_connector = google_vpc_access_connector.%s.self_link

depends_on = [google_project_iam_member.gcfadmin]
}
`, projectNumber, networkName, vpcConnectorName, bucketName, zipFilePath, functionName)
`, projectNumber, networkName, vpcConnectorName, vpcConnectorName, vpcIp, bucketName, zipFilePath, functionName, vpcConnectorName)
}

0 comments on commit f6b990a

Please sign in to comment.