diff --git a/docs/resources/redis_cluster.md b/docs/resources/redis_cluster.md index 278ab1a563..3d5ca0d286 100644 --- a/docs/resources/redis_cluster.md +++ b/docs/resources/redis_cluster.md @@ -129,7 +129,7 @@ keep in mind that you cannot downgrade a Redis Cluster so setting a smaller `clu by side. - Cluster mode (`cluster_size` > 1) : you can define a single private network as you create your cluster, you won't be - able to edit or detach it afterwards, unless you create another cluster. Your `service_ips` must be listed as follows: + able to edit or detach it afterward, unless you create another cluster. Your `service_ips` must be listed as follows: ```hcl service_ips = [ @@ -156,7 +156,8 @@ The `private_network` block supports : - `id` - (Required) The UUID of the private network resource. - `service_ips` - (Required) Endpoint IPv4 addresses in [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation). You must provide at - least one IP per node. + least one IP per node or The IP network address within the private subnet is determined by the IP Address Management (IPAM) + service if not set. ~> The `private_network` conflict with `acl`. Only one should be specified. diff --git a/scaleway/helpers_redis.go b/scaleway/helpers_redis.go index 37ff9cbeda..b17c553d0f 100644 --- a/scaleway/helpers_redis.go +++ b/scaleway/helpers_redis.go @@ -66,17 +66,22 @@ func expandRedisPrivateNetwork(data []interface{}) ([]*redis.EndpointSpec, error pnID := expandID(pn["id"].(string)) rawIPs := pn["service_ips"].([]interface{}) ips := []scw.IPNet(nil) - for _, rawIP := range rawIPs { - ip, err := expandIPNet(rawIP.(string)) - if err != nil { - return epSpecs, err - } - ips = append(ips, ip) - } spec := &redis.EndpointSpecPrivateNetworkSpec{ - ID: pnID, - ServiceIPs: ips, + ID: pnID, } + if len(rawIPs) != 0 { + for _, rawIP := range rawIPs { + ip, err := expandIPNet(rawIP.(string)) + if err != nil { + return epSpecs, err + } + ips = append(ips, ip) + } + spec.ServiceIPs = ips + } else { + spec.IpamConfig = &redis.EndpointSpecPrivateNetworkSpecIpamConfig{} + } + epSpecs = append(epSpecs, &redis.EndpointSpec{PrivateNetwork: spec}) } return epSpecs, nil diff --git a/scaleway/resource_redis_cluster.go b/scaleway/resource_redis_cluster.go index ca3c71017b..03b1395099 100644 --- a/scaleway/resource_redis_cluster.go +++ b/scaleway/resource_redis_cluster.go @@ -133,7 +133,7 @@ func resourceScalewayRedisCluster() *schema.Resource { }, "service_ips": { Type: schema.TypeList, - Required: true, + Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validation.IsCIDR, @@ -236,9 +236,9 @@ func resourceScalewayRedisClusterCreate(ctx context.Context, d *schema.ResourceD createReq.ClusterSettings = expandRedisSettings(settings) } - privN, privNExists := d.GetOk("private_network") - if privNExists { - pnSpecs, err := expandRedisPrivateNetwork(privN.(*schema.Set).List()) + pn, pnExists := d.GetOk("private_network") + if pnExists { + pnSpecs, err := expandRedisPrivateNetwork(pn.(*schema.Set).List()) if err != nil { return diag.FromErr(err) }