Skip to content

Commit 111fe72

Browse files
jremy42remyleone
andauthored
feat(redis): \authorize ha mode (#2833)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 9ed09eb commit 111fe72

File tree

4 files changed

+2795
-8
lines changed

4 files changed

+2795
-8
lines changed

docs/resources/redis_cluster.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ you cannot downgrade a Redis™ cluster.
100100

101101
- `cluster_size` - (Optional) The number of nodes in the Redis™ cluster.
102102

103-
~> **Important:** You cannot set `cluster_size` to 2, you either have to choose Standalone mode (1 node) or cluster mode
104-
which is minimum 3 (1 main node + 2 secondary nodes)
103+
~> **Important:**
104+
105+
- Cluster_size = 1 for Standalone mode (single node).
106+
107+
- Cluster_size = 2 for High Availability (HA) mode, with 1 main node and 1 standby node.
108+
109+
- Cluster_size >= 3 for Cluster mode, which requires a minimum of 1 main node and 2 secondary nodes.
105110

106111
~> **Important:** If you are using the cluster mode (>=3 nodes), you can set a bigger `cluster_size` than you initially
107112
did, it will migrate the Redis™ cluster but keep in mind that you cannot downgrade a Redis™ cluster, so setting a smaller

internal/services/redis/cluster.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package redis
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"io"
87
"strings"
@@ -222,11 +221,11 @@ func ResourceCluster() *schema.Resource {
222221

223222
func customizeDiffMigrateClusterSize() schema.CustomizeDiffFunc {
224223
return func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
225-
oldSize, newSize := diff.GetChange("cluster_size")
226-
if newSize == 2 {
227-
return errors.New("cluster_size can be either 1 (standalone) ou >3 (cluster mode), not 2")
228-
}
229-
if oldSize == 1 && newSize != 1 || newSize.(int) < oldSize.(int) {
224+
oldSizeRaw, newSizeRaw := diff.GetChange("cluster_size")
225+
oldSize, _ := oldSizeRaw.(int)
226+
newSize, _ := newSizeRaw.(int)
227+
228+
if oldSize == 1 && newSize != 1 || newSize < oldSize {
230229
return diff.ForceNew("cluster_size")
231230
}
232231
return nil

internal/services/redis/cluster_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,40 @@ func TestAccCluster_NoCertificate(t *testing.T) {
785785
})
786786
}
787787

788+
func TestAccCluster_MigrateToHAMode(t *testing.T) {
789+
tt := acctest.NewTestTools(t)
790+
defer tt.Cleanup()
791+
latestRedisVersion := getLatestVersion(tt)
792+
793+
resource.ParallelTest(t, resource.TestCase{
794+
PreCheck: func() { acctest.PreCheck(t) },
795+
ProviderFactories: tt.ProviderFactories,
796+
CheckDestroy: isClusterDestroyed(tt),
797+
Steps: []resource.TestStep{
798+
{
799+
Config: fmt.Sprintf(`
800+
resource "scaleway_redis_cluster" "main" {
801+
name = "test_redis_migrate_to_ha"
802+
version = "%s"
803+
node_type = "RED1-XS"
804+
user_name = "initial_user"
805+
password = "thiZ_is_v&ry_s3cret"
806+
cluster_size = 2
807+
tls_enabled = "true"
808+
zone = "fr-par-1"
809+
}
810+
`, latestRedisVersion),
811+
Check: resource.ComposeTestCheckFunc(
812+
isClusterPresent(tt, "scaleway_redis_cluster.main"),
813+
resource.TestCheckResourceAttr("scaleway_redis_cluster.main", "cluster_size", "2"),
814+
resource.TestCheckResourceAttr("scaleway_redis_cluster.main", "name", "test_redis_migrate_to_ha"),
815+
resource.TestCheckResourceAttr("scaleway_redis_cluster.main", "zone", "fr-par-1"),
816+
),
817+
},
818+
},
819+
})
820+
}
821+
788822
func isClusterDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
789823
return func(state *terraform.State) error {
790824
for _, rs := range state.RootModule().Resources {

0 commit comments

Comments
 (0)