@@ -220,6 +220,25 @@ func ResourcePool() *schema.Resource {
220220 Description : "The public IPv6 address of the node" ,
221221 Deprecated : "Please use the official Kubernetes provider and the kubernetes_nodes data source" ,
222222 },
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+ },
223242 },
224243 },
225244 },
@@ -228,25 +247,6 @@ func ResourcePool() *schema.Resource {
228247 Computed : true ,
229248 Description : "The status of the pool" ,
230249 },
231- "private_ips" : {
232- Type : schema .TypeList ,
233- Computed : true ,
234- Description : "List of private IPv4 addresses associated with the resource" ,
235- Elem : & schema.Resource {
236- Schema : map [string ]* schema.Schema {
237- "id" : {
238- Type : schema .TypeString ,
239- Computed : true ,
240- Description : "The ID of the IPv4 address resource" ,
241- },
242- "address" : {
243- Type : schema .TypeString ,
244- Computed : true ,
245- Description : "The private IPv4 address" ,
246- },
247- },
248- },
249- },
250250 },
251251 }
252252}
@@ -414,7 +414,6 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interfac
414414 _ = d .Set ("container_runtime" , pool .ContainerRuntime )
415415 _ = d .Set ("created_at" , pool .CreatedAt .Format (time .RFC3339 ))
416416 _ = d .Set ("updated_at" , pool .UpdatedAt .Format (time .RFC3339 ))
417- _ = d .Set ("nodes" , nodes )
418417 _ = d .Set ("status" , pool .Status )
419418 _ = d .Set ("kubelet_args" , flattenKubeletArgs (pool .KubeletArgs ))
420419 _ = d .Set ("region" , region )
@@ -426,36 +425,57 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interfac
426425 _ = d .Set ("placement_group_id" , zonal .NewID (pool .Zone , * pool .PlacementGroupID ).String ())
427426 }
428427
429- var allPrivateIPs []map [string ]interface {}
430-
431- for _ , nodeMap := range nodes {
432- nodeNameInterface , ok := nodeMap ["name" ]
433- if ! ok {
434- continue
435- }
436-
437- nodeName , ok := nodeNameInterface .(string )
438- if ! ok {
439- continue
440- }
441-
442- opts := & ipam.GetResourcePrivateIPsOptions {
443- ResourceName : & nodeName ,
444- }
445-
446- privateIPs , err := ipam .GetResourcePrivateIPs (ctx , m , region , opts )
447- if err != nil {
448- return diag .FromErr (err )
449- }
450-
451- if privateIPs != nil {
452- allPrivateIPs = append (allPrivateIPs , privateIPs ... )
428+ // Get nodes' private IPs
429+ diags := diag.Diagnostics {}
430+ projectID , err := getClusterProjectID (ctx , k8sAPI , pool )
431+ if err != nil {
432+ diags = append (diags , diag.Diagnostic {
433+ Severity : diag .Warning ,
434+ Summary : "Unable to get nodes private IPs" ,
435+ Detail : err .Error (),
436+ })
437+ } else {
438+ for i , nodeMap := range nodes {
439+ nodeNameInterface , ok := nodeMap ["name" ]
440+ if ! ok {
441+ continue
442+ }
443+
444+ nodeName , ok := nodeNameInterface .(string )
445+ if ! ok {
446+ continue
447+ }
448+
449+ opts := & ipam.GetResourcePrivateIPsOptions {
450+ ResourceName : & nodeName ,
451+ ProjectID : & projectID ,
452+ }
453+
454+ privateIPs , err := ipam .GetResourcePrivateIPs (ctx , m , region , opts )
455+ if err != nil {
456+ if httperrors .Is403 (err ) {
457+ diags = append (diags , diag.Diagnostic {
458+ Severity : diag .Warning ,
459+ Summary : "Unauthorized to read nodes' private IPs, please check your IAM permissions" ,
460+ Detail : err .Error (),
461+ })
462+ break
463+ } else {
464+ diags = append (diags , diag.Diagnostic {
465+ Severity : diag .Warning ,
466+ Summary : "Unable to get nodes private IPs from IPAM API" ,
467+ Detail : err .Error (),
468+ })
469+ }
470+ }
471+
472+ nodes [i ]["private_ips" ] = privateIPs
453473 }
454474 }
455475
456- _ = d .Set ("private_ips " , allPrivateIPs )
476+ _ = d .Set ("nodes " , nodes )
457477
458- return nil
478+ return diags
459479}
460480
461481func ResourceK8SPoolUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
0 commit comments