Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/resources/redis_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ you cannot downgrade a Redis™ cluster.

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

~> **Important:** You cannot set `cluster_size` to 2, you either have to choose Standalone mode (1 node) or cluster mode
which is minimum 3 (1 main node + 2 secondary nodes)
~> **Important:**

- Cluster_size = 1 for Standalone mode (single node).

- Cluster_size = 2 for High Availability (HA) mode, with 1 main node and 1 standby node.

- Cluster_size >= 3 for Cluster mode, which requires a minimum of 1 main node and 2 secondary nodes.

~> **Important:** If you are using the cluster mode (>=3 nodes), you can set a bigger `cluster_size` than you initially
did, it will migrate the Redis™ cluster but keep in mind that you cannot downgrade a Redis™ cluster, so setting a smaller
Expand Down
11 changes: 5 additions & 6 deletions internal/services/redis/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package redis

import (
"context"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -222,11 +221,11 @@ func ResourceCluster() *schema.Resource {

func customizeDiffMigrateClusterSize() schema.CustomizeDiffFunc {
return func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
oldSize, newSize := diff.GetChange("cluster_size")
if newSize == 2 {
return errors.New("cluster_size can be either 1 (standalone) ou >3 (cluster mode), not 2")
}
if oldSize == 1 && newSize != 1 || newSize.(int) < oldSize.(int) {
oldSizeRaw, newSizeRaw := diff.GetChange("cluster_size")
oldSize, _ := oldSizeRaw.(int)
newSize, _ := newSizeRaw.(int)

if oldSize == 1 && newSize != 1 || newSize < oldSize {
return diff.ForceNew("cluster_size")
}
return nil
Expand Down
34 changes: 34 additions & 0 deletions internal/services/redis/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,40 @@ func TestAccCluster_NoCertificate(t *testing.T) {
})
}

func TestAccCluster_MigrateToHAMode(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
latestRedisVersion := getLatestVersion(tt)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: isClusterDestroyed(tt),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "scaleway_redis_cluster" "main" {
name = "test_redis_migrate_to_ha"
version = "%s"
node_type = "RED1-XS"
user_name = "initial_user"
password = "thiZ_is_v&ry_s3cret"
cluster_size = 2
tls_enabled = "true"
zone = "fr-par-1"
}
`, latestRedisVersion),
Check: resource.ComposeTestCheckFunc(
isClusterPresent(tt, "scaleway_redis_cluster.main"),
resource.TestCheckResourceAttr("scaleway_redis_cluster.main", "cluster_size", "2"),
resource.TestCheckResourceAttr("scaleway_redis_cluster.main", "name", "test_redis_migrate_to_ha"),
resource.TestCheckResourceAttr("scaleway_redis_cluster.main", "zone", "fr-par-1"),
),
},
},
})
}

func isClusterDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
return func(state *terraform.State) error {
for _, rs := range state.RootModule().Resources {
Expand Down
Loading
Loading