Skip to content

Commit

Permalink
Read the function before patching it. (#4190) (#7723)
Browse files Browse the repository at this point in the history
* read the function before updating

* remove space

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 5, 2020
1 parent 94fa463 commit 0dc1132
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/4190.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudfunctions: fixed a bug with `google_cloudfunction_function` that blocked updates when Organization Policies are enabled.
```
12 changes: 7 additions & 5 deletions google/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0dc1132

Please sign in to comment.