Skip to content

Commit 1ecdf96

Browse files
Remove immutable annotation from nodeType to support vertical scaling for redis cluster. (#13190) (#9554)
[upstream:7d569ca387a821e42aa581b485a526e36a0ad4b9] Signed-off-by: Modular Magician <[email protected]>
1 parent e68212c commit 1ecdf96

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

.changelog/13190.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
redis: added update support for `google_redis_cluster` `node_type`
3+
```

google-beta/services/redis/resource_redis_cluster.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ resolution and up to nine fractional digits.`,
307307
Type: schema.TypeString,
308308
Computed: true,
309309
Optional: true,
310-
ForceNew: true,
311310
ValidateFunc: verify.ValidateEnum([]string{"REDIS_SHARED_CORE_NANO", "REDIS_HIGHMEM_MEDIUM", "REDIS_HIGHMEM_XLARGE", "REDIS_STANDARD_SMALL", ""}),
312311
Description: `The nodeType for the Redis cluster.
313312
If not provided, REDIS_HIGHMEM_MEDIUM will be used as default Possible values: ["REDIS_SHARED_CORE_NANO", "REDIS_HIGHMEM_MEDIUM", "REDIS_HIGHMEM_XLARGE", "REDIS_STANDARD_SMALL"]`,
@@ -928,6 +927,12 @@ func resourceRedisClusterUpdate(d *schema.ResourceData, meta interface{}) error
928927
billingProject = project
929928

930929
obj := make(map[string]interface{})
930+
nodeTypeProp, err := expandRedisClusterNodeType(d.Get("node_type"), d, config)
931+
if err != nil {
932+
return err
933+
} else if v, ok := d.GetOkExists("node_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nodeTypeProp)) {
934+
obj["nodeType"] = nodeTypeProp
935+
}
931936
pscConfigsProp, err := expandRedisClusterPscConfigs(d.Get("psc_configs"), d, config)
932937
if err != nil {
933938
return err
@@ -992,6 +997,10 @@ func resourceRedisClusterUpdate(d *schema.ResourceData, meta interface{}) error
992997
headers := make(http.Header)
993998
updateMask := []string{}
994999

1000+
if d.HasChange("node_type") {
1001+
updateMask = append(updateMask, "nodeType")
1002+
}
1003+
9951004
if d.HasChange("psc_configs") {
9961005
updateMask = append(updateMask, "pscConfigs")
9971006
}

google-beta/services/redis/resource_redis_cluster_test.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
1212
)
1313

14-
func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
14+
func TestAccRedisCluster_createUpdateClusterWithNodeType(t *testing.T) {
1515

1616
t.Parallel()
1717

@@ -23,7 +23,7 @@ func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
2323
CheckDestroy: testAccCheckRedisClusterDestroyProducer(t),
2424
Steps: []resource.TestStep{
2525
{
26-
// create cluster with replica count 1
26+
// create cluster with node type "REDIS_STANDARD_SMALL"
2727
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "TUESDAY", maintenanceHours: 2, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
2828
},
2929
{
@@ -32,9 +32,19 @@ func TestAccRedisCluster_createClusterWithNodeType(t *testing.T) {
3232
ImportStateVerify: true,
3333
ImportStateVerifyIgnore: []string{"psc_configs"},
3434
},
35+
{
36+
// update cluster with node type "REDIS_HIGHMEM_MEDIUM"
37+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: true, nodeType: "REDIS_HIGHMEM_MEDIUM", zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "TUESDAY", maintenanceHours: 2, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
38+
},
39+
{
40+
ResourceName: "google_redis_cluster.test",
41+
ImportState: true,
42+
ImportStateVerify: true,
43+
ImportStateVerifyIgnore: []string{"psc_configs"},
44+
},
3545
{
3646
// clean up the resource
37-
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: false, nodeType: "REDIS_STANDARD_SMALL", zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "TUESDAY", maintenanceHours: 2, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
47+
Config: createOrUpdateRedisCluster(&ClusterParams{name: name, replicaCount: 1, shardCount: 3, deletionProtectionEnabled: false, nodeType: "REDIS_HIGHMEM_MEDIUM", zoneDistributionMode: "MULTI_ZONE", maintenanceDay: "TUESDAY", maintenanceHours: 2, maintenanceMinutes: 0, maintenanceSeconds: 0, maintenanceNanos: 0}),
3848
},
3949
},
4050
})

0 commit comments

Comments
 (0)