@@ -13,6 +13,7 @@ import (
1313 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
1414 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1515 "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
16+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
1617 "github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
1718 "github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
1819)
@@ -192,6 +193,11 @@ func ResourcePool() *schema.Resource {
192193 Computed : true ,
193194 Elem : & schema.Resource {
194195 Schema : map [string ]* schema.Schema {
196+ "id" : {
197+ Type : schema .TypeString ,
198+ Computed : true ,
199+ Description : "The ID of the node" ,
200+ },
195201 "name" : {
196202 Type : schema .TypeString ,
197203 Computed : true ,
@@ -214,6 +220,25 @@ func ResourcePool() *schema.Resource {
214220 Description : "The public IPv6 address of the node" ,
215221 Deprecated : "Please use the official Kubernetes provider and the kubernetes_nodes data source" ,
216222 },
223+ "private_ips" : {
224+ Type : schema .TypeList ,
225+ Computed : true ,
226+ Description : "List of private IPv4 and IPv6 addresses associated with the node" ,
227+ Elem : & schema.Resource {
228+ Schema : map [string ]* schema.Schema {
229+ "id" : {
230+ Type : schema .TypeString ,
231+ Computed : true ,
232+ Description : "The ID of the IP address resource" ,
233+ },
234+ "address" : {
235+ Type : schema .TypeString ,
236+ Computed : true ,
237+ Description : "The private IP address" ,
238+ },
239+ },
240+ },
241+ },
217242 },
218243 },
219244 },
@@ -389,7 +414,6 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interfac
389414 _ = d .Set ("container_runtime" , pool .ContainerRuntime )
390415 _ = d .Set ("created_at" , pool .CreatedAt .Format (time .RFC3339 ))
391416 _ = d .Set ("updated_at" , pool .UpdatedAt .Format (time .RFC3339 ))
392- _ = d .Set ("nodes" , nodes )
393417 _ = d .Set ("status" , pool .Status )
394418 _ = d .Set ("kubelet_args" , flattenKubeletArgs (pool .KubeletArgs ))
395419 _ = d .Set ("region" , region )
@@ -401,7 +425,59 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interfac
401425 _ = d .Set ("placement_group_id" , zonal .NewID (pool .Zone , * pool .PlacementGroupID ).String ())
402426 }
403427
404- return nil
428+ // Get nodes' private IPs
429+ diags := diag.Diagnostics {}
430+
431+ projectID , err := getClusterProjectID (ctx , k8sAPI , pool )
432+ if err != nil {
433+ diags = append (diags , diag.Diagnostic {
434+ Severity : diag .Warning ,
435+ Summary : "Unable to get nodes private IPs" ,
436+ Detail : err .Error (),
437+ })
438+ } else {
439+ for i , nodeMap := range nodes {
440+ nodeNameInterface , ok := nodeMap ["name" ]
441+ if ! ok {
442+ continue
443+ }
444+
445+ nodeName , ok := nodeNameInterface .(string )
446+ if ! ok {
447+ continue
448+ }
449+
450+ opts := & ipam.GetResourcePrivateIPsOptions {
451+ ResourceName : & nodeName ,
452+ ProjectID : & projectID ,
453+ }
454+
455+ privateIPs , err := ipam .GetResourcePrivateIPs (ctx , m , region , opts )
456+ if err != nil {
457+ if httperrors .Is403 (err ) {
458+ diags = append (diags , diag.Diagnostic {
459+ Severity : diag .Warning ,
460+ Summary : "Unauthorized to read nodes' private IPs, please check your IAM permissions" ,
461+ Detail : err .Error (),
462+ })
463+
464+ break
465+ } else {
466+ diags = append (diags , diag.Diagnostic {
467+ Severity : diag .Warning ,
468+ Summary : "Unable to get nodes private IPs from IPAM API" ,
469+ Detail : err .Error (),
470+ })
471+ }
472+ }
473+
474+ nodes [i ]["private_ips" ] = privateIPs
475+ }
476+ }
477+
478+ _ = d .Set ("nodes" , nodes )
479+
480+ return diags
405481}
406482
407483func ResourceK8SPoolUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
0 commit comments