@@ -11,6 +11,7 @@ import (
11
11
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
12
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
13
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14
+ ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
14
15
lbSDK "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
15
16
"github.com/scaleway/scaleway-sdk-go/scw"
16
17
"github.com/scaleway/terraform-provider-scaleway/v2/internal/cdf"
@@ -20,6 +21,7 @@ import (
20
21
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
21
22
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
22
23
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
24
+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
23
25
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
24
26
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
25
27
)
@@ -199,6 +201,25 @@ func ResourceLb() *schema.Resource {
199
201
DiffSuppressFunc : dsf .OrderDiff ,
200
202
ConflictsWith : []string {"assign_flexible_ip" , "assign_flexible_ipv6" },
201
203
},
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
+ },
202
223
"region" : regional .ComputedSchema (),
203
224
"zone" : zonal .Schema (),
204
225
"organization_id" : account .OrganizationIDSchema (),
@@ -334,6 +355,32 @@ func resourceLbRead(ctx context.Context, d *schema.ResourceData, m interface{})
334
355
335
356
_ = d .Set ("private_network" , flattenPrivateNetworkConfigs (privateNetworks ))
336
357
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
+
337
384
return nil
338
385
}
339
386
0 commit comments