Skip to content

Commit

Permalink
feat(redis): enable ipam on private network
Browse files Browse the repository at this point in the history
  • Loading branch information
Monitob committed May 9, 2023
1 parent 68b3bfe commit afcd7fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
5 changes: 3 additions & 2 deletions docs/resources/redis_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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.

Expand Down
23 changes: 14 additions & 9 deletions scaleway/helpers_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions scaleway/resource_redis_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit afcd7fc

Please sign in to comment.