@@ -12,6 +12,7 @@ import (
1212 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1313 "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
1414 baremetalV3 "github.com/scaleway/scaleway-sdk-go/api/baremetal/v3"
15+ ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
1516 "github.com/scaleway/scaleway-sdk-go/scw"
1617 sdkValidation "github.com/scaleway/scaleway-sdk-go/validation"
1718 "github.com/scaleway/terraform-provider-scaleway/v2/internal/cdf"
@@ -21,6 +22,7 @@ import (
2122 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
2223 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
2324 "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
25+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
2426 "github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
2527 "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
2628)
@@ -268,6 +270,25 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument
268270 Optional : true ,
269271 Description : "The partitioning schema in json format" ,
270272 },
273+ "private_ips" : {
274+ Type : schema .TypeList ,
275+ Computed : true ,
276+ Description : "List of private IPv4 addresses associated with the resource" ,
277+ Elem : & schema.Resource {
278+ Schema : map [string ]* schema.Schema {
279+ "id" : {
280+ Type : schema .TypeString ,
281+ Computed : true ,
282+ Description : "The ID of the IPv4 address resource" ,
283+ },
284+ "address" : {
285+ Type : schema .TypeString ,
286+ Computed : true ,
287+ Description : "The private IPv4 address" ,
288+ },
289+ },
290+ },
291+ },
271292 },
272293 CustomizeDiff : customdiff .Sequence (
273294 customDiffOffer (),
@@ -508,6 +529,32 @@ func ResourceServerRead(ctx context.Context, d *schema.ResourceData, m interface
508529
509530 _ = d .Set ("private_network" , flattenPrivateNetworks (pnRegion , listPrivateNetworks .ServerPrivateNetworks ))
510531
532+ privateNetworkIDs := make ([]string , 0 , len (listPrivateNetworks .ServerPrivateNetworks ))
533+ for _ , pn := range listPrivateNetworks .ServerPrivateNetworks {
534+ privateNetworkIDs = append (privateNetworkIDs , pn .PrivateNetworkID )
535+ }
536+
537+ var allPrivateIPs []map [string ]interface {}
538+
539+ for _ , privateNetworkID := range privateNetworkIDs {
540+ resourceType := ipamAPI .ResourceTypeBaremetalPrivateNic
541+ opts := & ipam.GetResourcePrivateIPsOptions {
542+ ResourceType : & resourceType ,
543+ PrivateNetworkID : & privateNetworkID ,
544+ }
545+
546+ privateIPs , err := ipam .GetResourcePrivateIPs (ctx , m , pnRegion , opts )
547+ if err != nil {
548+ return diag .FromErr (err )
549+ }
550+
551+ if privateIPs != nil {
552+ allPrivateIPs = append (allPrivateIPs , privateIPs ... )
553+ }
554+ }
555+
556+ _ = d .Set ("private_ips" , allPrivateIPs )
557+
511558 return nil
512559}
513560
0 commit comments