@@ -6,10 +6,12 @@ import (
6
6
"fmt"
7
7
"io"
8
8
9
+ "github.com/hashicorp/go-cty/cty"
9
10
"github.com/hashicorp/terraform-plugin-log/tflog"
10
11
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
14
+ ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
13
15
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
14
16
"github.com/scaleway/scaleway-sdk-go/scw"
15
17
"github.com/scaleway/terraform-provider-scaleway/v2/internal/cdf"
@@ -18,6 +20,7 @@ import (
18
20
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
19
21
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
20
22
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
23
+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
21
24
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
22
25
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
23
26
)
@@ -322,6 +325,25 @@ func ResourceInstance() *schema.Resource {
322
325
Optional : true ,
323
326
Description : "Enable or disable encryption at rest for the database instance" ,
324
327
},
328
+ "private_ip" : {
329
+ Type : schema .TypeList ,
330
+ Computed : true ,
331
+ Description : "The private IPv4 address associated with the resource" ,
332
+ Elem : & schema.Resource {
333
+ Schema : map [string ]* schema.Schema {
334
+ "id" : {
335
+ Type : schema .TypeString ,
336
+ Computed : true ,
337
+ Description : "The ID of the IPv4 address resource" ,
338
+ },
339
+ "address" : {
340
+ Type : schema .TypeString ,
341
+ Computed : true ,
342
+ Description : "The private IPv4 address" ,
343
+ },
344
+ },
345
+ },
346
+ },
325
347
// Common
326
348
"region" : regional .Schema (),
327
349
"organization_id" : account .OrganizationIDSchema (),
@@ -640,15 +662,51 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte
640
662
_ = d .Set ("logs_policy" , flattenInstanceLogsPolicy (res .LogsPolicy ))
641
663
642
664
// set endpoints
665
+ privateIPs := make ([]map [string ]interface {}, 0 , 1 )
666
+ diags := diag.Diagnostics {}
667
+
643
668
if pnI , pnExist := flattenPrivateNetwork (res .Endpoints ); pnExist {
644
669
_ = d .Set ("private_network" , pnI )
670
+
671
+ for _ , endpoint := range res .Endpoints {
672
+ if endpoint .PrivateNetwork == nil {
673
+ continue
674
+ }
675
+
676
+ if endpoint .PrivateNetwork .ProvisioningMode == rdb .EndpointPrivateNetworkDetailsProvisioningModeIpam {
677
+ resourceType := ipamAPI .ResourceTypeRdbInstance
678
+ opts := & ipam.GetResourcePrivateIPsOptions {
679
+ ResourceID : & res .ID ,
680
+ ResourceType : & resourceType ,
681
+ PrivateNetworkID : & endpoint .PrivateNetwork .PrivateNetworkID ,
682
+ }
683
+
684
+ endpointPrivateIPs , err := ipam .GetResourcePrivateIPs (ctx , m , region , opts )
685
+ if err != nil {
686
+ if ! httperrors .Is403 (err ) {
687
+ return diag .FromErr (err )
688
+ }
689
+
690
+ diags = append (diags , diag.Diagnostic {
691
+ Severity : diag .Warning ,
692
+ Summary : err .Error (),
693
+ Detail : "Got 403 while reading private IP from IPAM API, please check your IAM permissions" ,
694
+ AttributePath : cty .GetAttrPath ("private_ip" ),
695
+ })
696
+ }
697
+
698
+ privateIPs = append (privateIPs , endpointPrivateIPs ... )
699
+ }
700
+ }
645
701
}
646
702
703
+ _ = d .Set ("private_ip" , privateIPs )
704
+
647
705
if lbI , lbExists := flattenLoadBalancer (res .Endpoints ); lbExists {
648
706
_ = d .Set ("load_balancer" , lbI )
649
707
}
650
708
651
- return nil
709
+ return diags
652
710
}
653
711
654
712
//gocyclo:ignore
0 commit comments