Skip to content

Commit 3435b9f

Browse files
fix for scaling down to zero replica in Valkey (#14219) (#23412)
[upstream:f1c7e99d36445008da325054523d3ab07de0b6b1] Signed-off-by: Modular Magician <[email protected]>
1 parent 0ca0b4b commit 3435b9f

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.changelog/14219.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
memorystore: added the ability to set the `replica_count`field in `google_memorystore_instance` to zero.
3+
```

google/services/memorystore/resource_memorystore_instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ func resourceMemorystoreInstanceCreate(d *schema.ResourceData, meta interface{})
953953
replicaCountProp, err := expandMemorystoreInstanceReplicaCount(d.Get("replica_count"), d, config)
954954
if err != nil {
955955
return err
956-
} else if v, ok := d.GetOkExists("replica_count"); !tpgresource.IsEmptyValue(reflect.ValueOf(replicaCountProp)) && (ok || !reflect.DeepEqual(v, replicaCountProp)) {
956+
} else if v, ok := d.GetOkExists("replica_count"); ok || !reflect.DeepEqual(v, replicaCountProp) {
957957
obj["replicaCount"] = replicaCountProp
958958
}
959959
authorizationModeProp, err := expandMemorystoreInstanceAuthorizationMode(d.Get("authorization_mode"), d, config)
@@ -1291,7 +1291,7 @@ func resourceMemorystoreInstanceUpdate(d *schema.ResourceData, meta interface{})
12911291
replicaCountProp, err := expandMemorystoreInstanceReplicaCount(d.Get("replica_count"), d, config)
12921292
if err != nil {
12931293
return err
1294-
} else if v, ok := d.GetOkExists("replica_count"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, replicaCountProp)) {
1294+
} else if v, ok := d.GetOkExists("replica_count"); ok || !reflect.DeepEqual(v, replicaCountProp) {
12951295
obj["replicaCount"] = replicaCountProp
12961296
}
12971297
shardCountProp, err := expandMemorystoreInstanceShardCount(d.Get("shard_count"), d, config)

google/services/memorystore/resource_memorystore_instance_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
3131
)
3232

33-
// Validate that replica count is updated for the instance
33+
// Validate that replica count is updated for the instance: 1->2->0
3434
func TestAccMemorystoreInstance_updateReplicaCount(t *testing.T) {
3535
t.Parallel()
3636

@@ -59,9 +59,18 @@ func TestAccMemorystoreInstance_updateReplicaCount(t *testing.T) {
5959
ImportState: true,
6060
ImportStateVerify: true,
6161
},
62+
{
63+
// update the replica count to 0
64+
Config: createOrUpdateMemorystoreInstance(&InstanceParams{name: name, replicaCount: 0, shardCount: 3, preventDestroy: true, zoneDistributionMode: "MULTI_ZONE", deletionProtectionEnabled: false, maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
65+
},
66+
{
67+
ResourceName: "google_memorystore_instance.test",
68+
ImportState: true,
69+
ImportStateVerify: true,
70+
},
6271
{
6372
// clean up the resource
64-
Config: createOrUpdateMemorystoreInstance(&InstanceParams{name: name, replicaCount: 2, shardCount: 3, preventDestroy: false, zoneDistributionMode: "MULTI_ZONE", deletionProtectionEnabled: false, maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
73+
Config: createOrUpdateMemorystoreInstance(&InstanceParams{name: name, replicaCount: 0, shardCount: 3, preventDestroy: false, zoneDistributionMode: "MULTI_ZONE", deletionProtectionEnabled: false, maintenanceDay: "MONDAY", maintenanceHours: 1, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
6574
},
6675
},
6776
})

0 commit comments

Comments
 (0)