Skip to content

Commit afa7df8

Browse files
decoders for backend services and consistent hash (#3468) (#2044)
Signed-off-by: Modular Magician <[email protected]>
1 parent 0ffb383 commit afa7df8

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

.changelog/3468.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
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`
3+
```

google-beta/resource_compute_backend_service.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,5 +3261,18 @@ func resourceComputeBackendServiceDecoder(d *schema.ResourceData, meta interface
32613261
delete(res, "iap")
32623262
}
32633263

3264+
// Requests with consistentHash will error for specific values of
3265+
// localityLbPolicy. However, the API will not remove it if the backend
3266+
// service is updated to from supporting to non-supporting localityLbPolicy
3267+
// (e.g. RING_HASH to RANDOM), which causes an error on subsequent update.
3268+
// In order to prevent errors, we ignore any consistentHash returned
3269+
// from the API when the localityLbPolicy doesn't support it.
3270+
if v, ok := res["localityLbPolicy"]; ok {
3271+
lbPolicy := v.(string)
3272+
if lbPolicy != "MAGLEV" && lbPolicy != "RING_HASH" {
3273+
delete(res, "consistentHash")
3274+
}
3275+
}
3276+
32643277
return res, nil
32653278
}

google-beta/resource_compute_region_backend_service.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,18 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
10001000
return handleNotFoundError(err, d, fmt.Sprintf("ComputeRegionBackendService %q", d.Id()))
10011001
}
10021002

1003+
res, err = resourceComputeRegionBackendServiceDecoder(d, meta, res)
1004+
if err != nil {
1005+
return err
1006+
}
1007+
1008+
if res == nil {
1009+
// Decoding the object has resulted in it being gone. It may be marked deleted
1010+
log.Printf("[DEBUG] Removing ComputeRegionBackendService because it no longer exists.")
1011+
d.SetId("")
1012+
return nil
1013+
}
1014+
10031015
if err := d.Set("project", project); err != nil {
10041016
return fmt.Errorf("Error reading RegionBackendService: %s", err)
10051017
}
@@ -2895,3 +2907,20 @@ func resourceComputeRegionBackendServiceEncoder(d *schema.ResourceData, meta int
28952907
obj["backends"] = backends
28962908
return obj, nil
28972909
}
2910+
2911+
func resourceComputeRegionBackendServiceDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
2912+
// Requests with consistentHash will error for specific values of
2913+
// localityLbPolicy. However, the API will not remove it if the backend
2914+
// service is updated to from supporting to non-supporting localityLbPolicy
2915+
// (e.g. RING_HASH to RANDOM), which causes an error on subsequent update.
2916+
// In order to prevent errors, we ignore any consistentHash returned
2917+
// from the API when the localityLbPolicy doesn't support it.
2918+
if v, ok := res["localityLbPolicy"]; ok {
2919+
lbPolicy := v.(string)
2920+
if lbPolicy != "MAGLEV" && lbPolicy != "RING_HASH" {
2921+
delete(res, "consistentHash")
2922+
}
2923+
}
2924+
2925+
return res, nil
2926+
}

0 commit comments

Comments
 (0)