@@ -11,6 +11,7 @@ import (
1111 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1212 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1313 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
14+ ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
1415 "github.com/scaleway/scaleway-sdk-go/api/redis/v1"
1516 "github.com/scaleway/scaleway-sdk-go/scw"
1617 "github.com/scaleway/terraform-provider-scaleway/v2/internal/cdf"
@@ -19,6 +20,7 @@ import (
1920 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
2021 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
2122 "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
23+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
2224 "github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
2325 "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
2426)
@@ -193,6 +195,25 @@ func ResourceCluster() *schema.Resource {
193195 },
194196 },
195197 },
198+ "private_ips" : {
199+ Type : schema .TypeList ,
200+ Computed : true ,
201+ Description : "List of private IP addresses associated with the resource" ,
202+ Elem : & schema.Resource {
203+ Schema : map [string ]* schema.Schema {
204+ "id" : {
205+ Type : schema .TypeString ,
206+ Computed : true ,
207+ Description : "The ID of the IP address resource" ,
208+ },
209+ "address" : {
210+ Type : schema .TypeString ,
211+ Computed : true ,
212+ Description : "The private IP address" ,
213+ },
214+ },
215+ },
216+ },
196217 "certificate" : {
197218 Type : schema .TypeString ,
198219 Computed : true ,
@@ -344,11 +365,46 @@ func ResourceClusterRead(ctx context.Context, d *schema.ResourceData, m interfac
344365 }
345366
346367 // set endpoints
368+ var allPrivateIPs []map [string ]interface {}
369+
347370 pnI , pnExists := flattenPrivateNetwork (cluster .Endpoints )
348371 if pnExists {
349372 _ = d .Set ("private_network" , pnI )
373+
374+ privateNetworkIDs := []string (nil )
375+
376+ for _ , endpoint := range cluster .Endpoints {
377+ if endpoint .PrivateNetwork != nil {
378+ privateNetworkIDs = append (privateNetworkIDs , endpoint .PrivateNetwork .ID )
379+ }
380+ }
381+
382+ resourceType := ipamAPI .ResourceTypeRedisCluster
383+
384+ region , err := zone .Region ()
385+ if err != nil {
386+ return diag .FromErr (err )
387+ }
388+
389+ for _ , privateNetworkID := range privateNetworkIDs {
390+ opts := & ipam.GetResourcePrivateIPsOptions {
391+ ResourceType : & resourceType ,
392+ PrivateNetworkID : & privateNetworkID ,
393+ ResourceID : & cluster .ID ,
394+ }
395+
396+ privateIPs , err := ipam .GetResourcePrivateIPs (ctx , m , region , opts )
397+ if err != nil {
398+ return diag .FromErr (err )
399+ }
400+
401+ if privateIPs != nil {
402+ allPrivateIPs = append (allPrivateIPs , privateIPs ... )
403+ }
404+ }
350405 }
351406
407+ _ = d .Set ("private_ips" , allPrivateIPs )
352408 _ = d .Set ("public_network" , flattenPublicNetwork (cluster .Endpoints ))
353409
354410 if cluster .TLSEnabled {
0 commit comments