Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redis): enable ipam on private network #1925

Merged
merged 1 commit into from
May 10, 2023
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
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