@@ -13,6 +13,7 @@ import (
13
13
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
14
14
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
15
15
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
16
+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
16
17
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
17
18
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
18
19
)
@@ -192,6 +193,11 @@ func ResourcePool() *schema.Resource {
192
193
Computed : true ,
193
194
Elem : & schema.Resource {
194
195
Schema : map [string ]* schema.Schema {
196
+ "id" : {
197
+ Type : schema .TypeString ,
198
+ Computed : true ,
199
+ Description : "The ID of the node" ,
200
+ },
195
201
"name" : {
196
202
Type : schema .TypeString ,
197
203
Computed : true ,
@@ -214,6 +220,25 @@ func ResourcePool() *schema.Resource {
214
220
Description : "The public IPv6 address of the node" ,
215
221
Deprecated : "Please use the official Kubernetes provider and the kubernetes_nodes data source" ,
216
222
},
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
+ },
217
242
},
218
243
},
219
244
},
@@ -389,7 +414,6 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interfac
389
414
_ = d .Set ("container_runtime" , pool .ContainerRuntime )
390
415
_ = d .Set ("created_at" , pool .CreatedAt .Format (time .RFC3339 ))
391
416
_ = d .Set ("updated_at" , pool .UpdatedAt .Format (time .RFC3339 ))
392
- _ = d .Set ("nodes" , nodes )
393
417
_ = d .Set ("status" , pool .Status )
394
418
_ = d .Set ("kubelet_args" , flattenKubeletArgs (pool .KubeletArgs ))
395
419
_ = d .Set ("region" , region )
@@ -401,7 +425,59 @@ func ResourceK8SPoolRead(ctx context.Context, d *schema.ResourceData, m interfac
401
425
_ = d .Set ("placement_group_id" , zonal .NewID (pool .Zone , * pool .PlacementGroupID ).String ())
402
426
}
403
427
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
405
481
}
406
482
407
483
func ResourceK8SPoolUpdate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
0 commit comments