Skip to content

Commit e270165

Browse files
committed
feat(redis): \authorize ha mode
1 parent ad60c88 commit e270165

File tree

4 files changed

+2802
-5
lines changed

4 files changed

+2802
-5
lines changed

docs/resources/redis_cluster.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ 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+
- Cluster_size = 1 for Standalone mode (single node).
105+
106+
- Cluster_size = 2 for High Availability (HA) mode, with 1 main node and 1 standby node.
107+
108+
- Cluster_size >= 3 for Cluster mode, which requires a minimum of 1 main node and 2 secondary nodes.
105109

106110
~> **Important:** If you are using the cluster mode (>=3 nodes), you can set a bigger `cluster_size` than you initially
107111
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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,22 @@ func ResourceCluster() *schema.Resource {
223223
func customizeDiffMigrateClusterSize() schema.CustomizeDiffFunc {
224224
return func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
225225
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")
226+
227+
newSizeInt := newSize.(int)
228+
oldSizeInt := oldSize.(int)
229+
230+
if oldSizeInt == 1 && newSizeInt == 3 {
231+
return nil
228232
}
229-
if oldSize == 1 && newSize != 1 || newSize.(int) < oldSize.(int) {
233+
234+
if newSizeInt == 2 || newSizeInt <= 0 {
235+
return errors.New("invalid cluster_size: must be 1 (standalone), 3 (cluster mode), or higher in certain configurations")
236+
}
237+
238+
if newSizeInt < oldSizeInt || (oldSizeInt != 1 && newSizeInt == 1) {
230239
return diff.ForceNew("cluster_size")
231240
}
241+
232242
return nil
233243
}
234244
}

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)