Skip to content

Commit 931bfcd

Browse files
authoredMay 10, 2023
feat(redis): enable ipam on private network (#1925)
1 parent f8e2a7e commit 931bfcd

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed
 

‎docs/resources/redis_cluster.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ keep in mind that you cannot downgrade a Redis Cluster so setting a smaller `clu
129129
by side.
130130

131131
- Cluster mode (`cluster_size` > 1) : you can define a single private network as you create your cluster, you won't be
132-
able to edit or detach it afterwards, unless you create another cluster. Your `service_ips` must be listed as follows:
132+
able to edit or detach it afterward, unless you create another cluster. Your `service_ips` must be listed as follows:
133133

134134
```hcl
135135
service_ips = [
@@ -156,7 +156,8 @@ The `private_network` block supports :
156156
- `id` - (Required) The UUID of the private network resource.
157157
- `service_ips` - (Required) Endpoint IPv4 addresses
158158
in [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation). You must provide at
159-
least one IP per node.
159+
least one IP per node or The IP network address within the private subnet is determined by the IP Address Management (IPAM)
160+
service if not set.
160161

161162
~> The `private_network` conflict with `acl`. Only one should be specified.
162163

‎scaleway/helpers_redis.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,22 @@ func expandRedisPrivateNetwork(data []interface{}) ([]*redis.EndpointSpec, error
6666
pnID := expandID(pn["id"].(string))
6767
rawIPs := pn["service_ips"].([]interface{})
6868
ips := []scw.IPNet(nil)
69-
for _, rawIP := range rawIPs {
70-
ip, err := expandIPNet(rawIP.(string))
71-
if err != nil {
72-
return epSpecs, err
73-
}
74-
ips = append(ips, ip)
75-
}
7669
spec := &redis.EndpointSpecPrivateNetworkSpec{
77-
ID: pnID,
78-
ServiceIPs: ips,
70+
ID: pnID,
7971
}
72+
if len(rawIPs) != 0 {
73+
for _, rawIP := range rawIPs {
74+
ip, err := expandIPNet(rawIP.(string))
75+
if err != nil {
76+
return epSpecs, err
77+
}
78+
ips = append(ips, ip)
79+
}
80+
spec.ServiceIPs = ips
81+
} else {
82+
spec.IpamConfig = &redis.EndpointSpecPrivateNetworkSpecIpamConfig{}
83+
}
84+
8085
epSpecs = append(epSpecs, &redis.EndpointSpec{PrivateNetwork: spec})
8186
}
8287
return epSpecs, nil

‎scaleway/resource_redis_cluster.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func resourceScalewayRedisCluster() *schema.Resource {
133133
},
134134
"service_ips": {
135135
Type: schema.TypeList,
136-
Required: true,
136+
Optional: true,
137137
Elem: &schema.Schema{
138138
Type: schema.TypeString,
139139
ValidateFunc: validation.IsCIDR,
@@ -236,9 +236,9 @@ func resourceScalewayRedisClusterCreate(ctx context.Context, d *schema.ResourceD
236236
createReq.ClusterSettings = expandRedisSettings(settings)
237237
}
238238

239-
privN, privNExists := d.GetOk("private_network")
240-
if privNExists {
241-
pnSpecs, err := expandRedisPrivateNetwork(privN.(*schema.Set).List())
239+
pn, pnExists := d.GetOk("private_network")
240+
if pnExists {
241+
pnSpecs, err := expandRedisPrivateNetwork(pn.(*schema.Set).List())
242242
if err != nil {
243243
return diag.FromErr(err)
244244
}

0 commit comments

Comments
 (0)
Please sign in to comment.