Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read the function before patching it. #7723

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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