@@ -11,6 +11,7 @@ import (
1111 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1212 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1313 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14+ ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
1415 lbSDK "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
1516 "github.com/scaleway/scaleway-sdk-go/scw"
1617 "github.com/scaleway/terraform-provider-scaleway/v2/internal/cdf"
@@ -20,6 +21,7 @@ import (
2021 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
2122 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
2223 "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
24+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
2325 "github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
2426 "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
2527)
@@ -199,6 +201,25 @@ func ResourceLb() *schema.Resource {
199201 DiffSuppressFunc : dsf .OrderDiff ,
200202 ConflictsWith : []string {"assign_flexible_ip" , "assign_flexible_ipv6" },
201203 },
204+ "private_ips" : {
205+ Type : schema .TypeList ,
206+ Computed : true ,
207+ Description : "List of private IPv4 and IPv6 addresses associated with the resource" ,
208+ Elem : & schema.Resource {
209+ Schema : map [string ]* schema.Schema {
210+ "id" : {
211+ Type : schema .TypeString ,
212+ Computed : true ,
213+ Description : "The ID of the IP address resource" ,
214+ },
215+ "address" : {
216+ Type : schema .TypeString ,
217+ Computed : true ,
218+ Description : "The private IP address" ,
219+ },
220+ },
221+ },
222+ },
202223 "region" : regional .ComputedSchema (),
203224 "zone" : zonal .Schema (),
204225 "organization_id" : account .OrganizationIDSchema (),
@@ -334,6 +355,32 @@ func resourceLbRead(ctx context.Context, d *schema.ResourceData, m interface{})
334355
335356 _ = d .Set ("private_network" , flattenPrivateNetworkConfigs (privateNetworks ))
336357
358+ privateNetworkIDs := make ([]string , 0 , len (privateNetworks ))
359+ for _ , pn := range privateNetworks {
360+ privateNetworkIDs = append (privateNetworkIDs , pn .PrivateNetworkID )
361+ }
362+
363+ allPrivateIPs := []map [string ]interface {}(nil )
364+ resourceType := ipamAPI .ResourceTypeLBServer
365+
366+ for _ , privateNetworkID := range privateNetworkIDs {
367+ opts := & ipam.GetResourcePrivateIPsOptions {
368+ ResourceType : & resourceType ,
369+ PrivateNetworkID : & privateNetworkID ,
370+ }
371+
372+ privateIPs , err := ipam .GetResourcePrivateIPs (ctx , m , region , opts )
373+ if err != nil {
374+ return diag .FromErr (err )
375+ }
376+
377+ if privateIPs != nil {
378+ allPrivateIPs = append (allPrivateIPs , privateIPs ... )
379+ }
380+ }
381+
382+ _ = d .Set ("private_ips" , allPrivateIPs )
383+
337384 return nil
338385}
339386
0 commit comments