hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

google_cloudfunctions_function unable to remove vpc_connector if vpc_connector_egress_settings previously set #11719

Open mattalbr opened 2 years ago

mattalbr commented 2 years ago

Community Note

Terraform Version

Terraform v1.1.8 on linux_arm64

Affected Resource(s)

Terraform Configuration Files

Before:

resource "google_cloudfunctions_function" "patient_data_uploader_function" {
  name        = "patient-data-uploader-function"
  description = "Uploads patient data to spreadsheet"
  runtime     = "python310"
  region      = var.region

  available_memory_mb           = 512
  source_archive_bucket         = google_storage_bucket.cloud_function_bucket.name
  source_archive_object         = google_storage_bucket_object.patient_data_uploader_zip.name
  timeout                       = 60
  entry_point                   = "upload_patient_data"
  max_instances                 = 1
  service_account_email         = google_service_account.patient_data_uploader_user.email
  vpc_connector                 = google_vpc_access_connector.connector.self_link
  vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY"

  event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource   = google_pubsub_topic.patient_data_uploader_trigger_topic.id
  }
}

AFter

resource "google_cloudfunctions_function" "patient_data_uploader_function" {
  name        = "patient-data-uploader-function"
  description = "Uploads patient data to spreadsheet"
  runtime     = "python310"
  region      = var.region

  available_memory_mb           = 512
  source_archive_bucket         = google_storage_bucket.cloud_function_bucket.name
  source_archive_object         = google_storage_bucket_object.patient_data_uploader_zip.name
  timeout                       = 60
  entry_point                   = "upload_patient_data"
  max_instances                 = 1
  service_account_email         = google_service_account.patient_data_uploader_user.email
  #vpc_connector                 = google_vpc_access_connector.connector.self_link
  #vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY"

  event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource   = google_pubsub_topic.patient_data_uploader_trigger_topic.id
  }
}

Debug Output

Panic Output

Expected Behavior

The function should have been updated with the vpc connector removed.

Actual Behavior

Error: Error while updating cloudfunction configuration: googleapi: Error 400: The request has errors │ Details: │ [ │ { │ "@type": "type.googleapis.com/google.rpc.BadRequest", │ "fieldViolations": [ │ { │ "description": "\"vpc_connector_egress_settings\" requires \"vpc_connector\" field to be set.", │ "field": "vpc_connector_egress_settings" │ } │ ] │ } │ ] │ , badRequest │ │ with google_cloudfunctions_function.patient_data_uploader_function, │ on main.tf line 376, in resource "google_cloudfunctions_function" "patient_data_uploader_function": │ 376: resource "google_cloudfunctions_function" "patient_data_uploader_function" {

Steps to Reproduce

  1. terraform apply first config
  2. terraform apply second config

Important Factoids

This also seemed to fail when I tried via command line: cloud functions deploy patient-data-uploader-function --clear-vpc-connector

I had to manually change via UI to get this to work.

References

b/274818550

sangngocle commented 8 months ago

Hi @mattalbr, is there any update regarding this one? Do you have any workaround or something? I have the same issue and would like to hear any info from you.

sewei9 commented 1 month ago

Just stumbled upon the same error. Removing the existing settings manually from GCP and redeploy vpc config worked for me.