diff --git a/.changelog/4190.txt b/.changelog/4190.txt new file mode 100644 index 00000000000..2fa6a96adb9 --- /dev/null +++ b/.changelog/4190.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +cloudfunctions: fixed a bug with `google_cloudfunction_function` that blocked updates when Organization Policies are enabled. +``` diff --git a/google/resource_cloudfunctions_function.go b/google/resource_cloudfunctions_function.go index baf0d9523e3..5c1b6192efb 100644 --- a/google/resource_cloudfunctions_function.go +++ b/google/resource_cloudfunctions_function.go @@ -580,12 +580,14 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro return err } - d.Partial(true) - - function := cloudfunctions.CloudFunction{ - Name: cloudFuncId.cloudFunctionId(), + // The full function needs to supplied in the PATCH call to evaluate some Organization Policies. https://github.com/hashicorp/terraform-provider-google/issues/6603 + function, err := config.NewCloudFunctionsClient(userAgent).Projects.Locations.Functions.Get(cloudFuncId.cloudFunctionId()).Do() + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("Target CloudFunctions Function %q", cloudFuncId.Name)) } + d.Partial(true) + var updateMaskArr []string if d.HasChange("available_memory_mb") { availableMemoryMb := d.Get("available_memory_mb").(int) @@ -663,7 +665,7 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro if len(updateMaskArr) > 0 { log.Printf("[DEBUG] Send Patch CloudFunction Configuration request: %#v", function) updateMask := strings.Join(updateMaskArr, ",") - op, err := config.NewCloudFunctionsClient(userAgent).Projects.Locations.Functions.Patch(function.Name, &function). + op, err := config.NewCloudFunctionsClient(userAgent).Projects.Locations.Functions.Patch(function.Name, function). UpdateMask(updateMask).Do() if err != nil {