Skip to content

Commit e73f468

Browse files
Read the function before patching it. (#4190) (#2681)
* read the function before updating * remove space Signed-off-by: Modular Magician <[email protected]>
1 parent 01be346 commit e73f468

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changelog/4190.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudfunctions: fixed a bug with `google_cloudfunction_function` that blocked updates when Organization Policies are enabled.
3+
```

google-beta/resource_cloudfunctions_function.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,14 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
580580
return err
581581
}
582582

583-
d.Partial(true)
584-
585-
function := cloudfunctions.CloudFunction{
586-
Name: cloudFuncId.cloudFunctionId(),
583+
// The full function needs to supplied in the PATCH call to evaluate some Organization Policies. https://github.com/hashicorp/terraform-provider-google/issues/6603
584+
function, err := config.NewCloudFunctionsClient(userAgent).Projects.Locations.Functions.Get(cloudFuncId.cloudFunctionId()).Do()
585+
if err != nil {
586+
return handleNotFoundError(err, d, fmt.Sprintf("Target CloudFunctions Function %q", cloudFuncId.Name))
587587
}
588588

589+
d.Partial(true)
590+
589591
var updateMaskArr []string
590592
if d.HasChange("available_memory_mb") {
591593
availableMemoryMb := d.Get("available_memory_mb").(int)
@@ -663,7 +665,7 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
663665
if len(updateMaskArr) > 0 {
664666
log.Printf("[DEBUG] Send Patch CloudFunction Configuration request: %#v", function)
665667
updateMask := strings.Join(updateMaskArr, ",")
666-
op, err := config.NewCloudFunctionsClient(userAgent).Projects.Locations.Functions.Patch(function.Name, &function).
668+
op, err := config.NewCloudFunctionsClient(userAgent).Projects.Locations.Functions.Patch(function.Name, function).
667669
UpdateMask(updateMask).Do()
668670

669671
if err != nil {

0 commit comments

Comments
 (0)