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

Remove unsupported consistent hash for backend services in decoder #6316

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/3468.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: Remove permadiff or errors on update for `google_compute_backend_service` and `google_compute_region_backend_service` when `consistent_hash` values were previously set on backend service but are not supported by updated value of `locality_lb_policy`
```
13 changes: 13 additions & 0 deletions google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3144,5 +3144,18 @@ func resourceComputeBackendServiceDecoder(d *schema.ResourceData, meta interface
delete(res, "iap")
}

// Requests with consistentHash will error for specific values of
// localityLbPolicy. However, the API will not remove it if the backend
// service is updated to from supporting to non-supporting localityLbPolicy
// (e.g. RING_HASH to RANDOM), which causes an error on subsequent update.
// In order to prevent errors, we ignore any consistentHash returned
// from the API when the localityLbPolicy doesn't support it.
if v, ok := res["localityLbPolicy"]; ok {
lbPolicy := v.(string)
if lbPolicy != "MAGLEV" && lbPolicy != "RING_HASH" {
delete(res, "consistentHash")
}
}

return res, nil
}
29 changes: 29 additions & 0 deletions google/resource_compute_region_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,18 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
return handleNotFoundError(err, d, fmt.Sprintf("ComputeRegionBackendService %q", d.Id()))
}

res, err = resourceComputeRegionBackendServiceDecoder(d, meta, res)
if err != nil {
return err
}

if res == nil {
// Decoding the object has resulted in it being gone. It may be marked deleted
log.Printf("[DEBUG] Removing ComputeRegionBackendService because it no longer exists.")
d.SetId("")
return nil
}

if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading RegionBackendService: %s", err)
}
Expand Down Expand Up @@ -2778,3 +2790,20 @@ func resourceComputeRegionBackendServiceEncoder(d *schema.ResourceData, meta int
obj["backends"] = backends
return obj, nil
}

func resourceComputeRegionBackendServiceDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
// Requests with consistentHash will error for specific values of
// localityLbPolicy. However, the API will not remove it if the backend
// service is updated to from supporting to non-supporting localityLbPolicy
// (e.g. RING_HASH to RANDOM), which causes an error on subsequent update.
// In order to prevent errors, we ignore any consistentHash returned
// from the API when the localityLbPolicy doesn't support it.
if v, ok := res["localityLbPolicy"]; ok {
lbPolicy := v.(string)
if lbPolicy != "MAGLEV" && lbPolicy != "RING_HASH" {
delete(res, "consistentHash")
}
}

return res, nil
}