Skip to content

Commit

Permalink
feat(redis): \authorize ha mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jremy42 committed Dec 3, 2024
1 parent ad60c88 commit 11c3326
Show file tree
Hide file tree
Showing 4 changed files with 2,794 additions and 5 deletions.
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
7 changes: 4 additions & 3 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 @@ -223,9 +222,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 newSize == 2 || newSize.(int) > 3 || newSize.(int) == 1 {
return nil
}

if oldSize == 1 && newSize != 1 || newSize.(int) < oldSize.(int) {
return diff.ForceNew("cluster_size")
}
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

0 comments on commit 11c3326

Please sign in to comment.