88 "strings"
99 "time"
1010
11- matlas "go.mongodb.org/atlas/mongodbatlas "
11+ "go.mongodb.org/atlas-sdk/v20231115005/admin "
1212
1313 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1414 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -26,11 +26,11 @@ const (
2626
2727func Resource () * schema.Resource {
2828 return & schema.Resource {
29- CreateContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveCreate ,
30- ReadContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveRead ,
31- DeleteContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveDelete ,
29+ CreateContext : resourceCreate ,
30+ ReadContext : resourceRead ,
31+ DeleteContext : resourceDelete ,
3232 Importer : & schema.ResourceImporter {
33- StateContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveImportState ,
33+ StateContext : resourceImport ,
3434 },
3535 Schema : map [string ]* schema.Schema {
3636 "project_id" : {
@@ -65,12 +65,12 @@ func Resource() *schema.Resource {
6565 }
6666}
6767
68- func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveCreate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
69- conn := meta .(* config.MongoDBClient ).Atlas
68+ func resourceCreate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
69+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
7070 projectID := d .Get ("project_id" ).(string )
7171 endpointID := d .Get ("endpoint_id" ).(string )
7272
73- _ , _ , err := conn . DataLakes . CreatePrivateLinkEndpoint (ctx , projectID , newPrivateLinkEndpointDataLake (d ))
73+ _ , _ , err := connV2 . DataFederationApi . CreateDataFederationPrivateEndpoint (ctx , projectID , newPrivateNetworkEndpointIDEntry (d )). Execute ( )
7474 if err != nil {
7575 return diag .FromErr (fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveCreate , projectID , err ))
7676 }
@@ -80,47 +80,46 @@ func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveCr
8080 "endpoint_id" : endpointID ,
8181 }))
8282
83- return resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveRead (ctx , d , meta )
83+ return resourceRead (ctx , d , meta )
8484}
8585
86- func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
87- conn := meta .(* config.MongoDBClient ).Atlas
86+ func resourceRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
87+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
8888 ids := conversion .DecodeStateID (d .Id ())
8989 projectID := ids ["project_id" ]
9090 endopointID := ids ["endpoint_id" ]
9191
92- privateEndpoint , resp , err := conn . DataLakes . GetPrivateLinkEndpoint ( context . Background () , projectID , endopointID )
92+ privateEndpoint , resp , err := connV2 . DataFederationApi . GetDataFederationPrivateEndpoint ( ctx , projectID , endopointID ). Execute ( )
9393 if err != nil {
9494 if resp != nil && resp .StatusCode == http .StatusNotFound {
9595 d .SetId ("" )
9696 return nil
9797 }
98-
9998 return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
10099 }
101100
102- if err := d .Set ("comment" , privateEndpoint .Comment ); err != nil {
101+ if err := d .Set ("comment" , privateEndpoint .GetComment () ); err != nil {
103102 return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
104103 }
105104
106- if err := d .Set ("provider_name" , privateEndpoint .Provider ); err != nil {
105+ if err := d .Set ("provider_name" , privateEndpoint .GetProvider () ); err != nil {
107106 return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
108107 }
109108
110- if err := d .Set ("type" , privateEndpoint .Type ); err != nil {
109+ if err := d .Set ("type" , privateEndpoint .GetType () ); err != nil {
111110 return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
112111 }
113112
114113 return nil
115114}
116115
117- func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveDelete (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
118- conn := meta .(* config.MongoDBClient ).Atlas
116+ func resourceDelete (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
117+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
119118 ids := conversion .DecodeStateID (d .Id ())
120119 projectID := ids ["project_id" ]
121120 endpointID := ids ["endpoint_id" ]
122121
123- _ , err := conn . DataLakes . DeletePrivateLinkEndpoint (ctx , projectID , endpointID )
122+ _ , _ , err := connV2 . DataFederationApi . DeleteDataFederationPrivateEndpoint (ctx , projectID , endpointID ). Execute ( )
124123 if err != nil {
125124 return diag .FromErr (fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveDelete , endpointID , projectID , err ))
126125 }
@@ -130,31 +129,31 @@ func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveDe
130129 return nil
131130}
132131
133- func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveImportState (ctx context.Context , d * schema.ResourceData , meta any ) ([]* schema.ResourceData , error ) {
134- conn := meta .(* config.MongoDBClient ).Atlas
132+ func resourceImport (ctx context.Context , d * schema.ResourceData , meta any ) ([]* schema.ResourceData , error ) {
133+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
135134 projectID , endpointID , err := splitAtlasPrivatelinkEndpointServiceDataFederationOnlineArchive (d .Id ())
136135 if err != nil {
137136 return nil , err
138137 }
139138
140- privateEndpoint , _ , err := conn . DataLakes . GetPrivateLinkEndpoint (ctx , projectID , endpointID )
139+ privateEndpoint , _ , err := connV2 . DataFederationApi . GetDataFederationPrivateEndpoint (ctx , projectID , endpointID ). Execute ( )
141140 if err != nil {
142141 return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
143142 }
144143
145- if err := d .Set ("comment" , privateEndpoint .Comment ); err != nil {
144+ if err := d .Set ("comment" , privateEndpoint .GetComment () ); err != nil {
146145 return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
147146 }
148147
149- if err := d .Set ("provider_name" , privateEndpoint .Provider ); err != nil {
148+ if err := d .Set ("provider_name" , privateEndpoint .GetProvider () ); err != nil {
150149 return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
151150 }
152151
153- if err := d .Set ("type" , privateEndpoint .Type ); err != nil {
152+ if err := d .Set ("type" , privateEndpoint .GetType () ); err != nil {
154153 return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
155154 }
156155
157- if err := d .Set ("endpoint_id" , privateEndpoint .EndpointID ); err != nil {
156+ if err := d .Set ("endpoint_id" , privateEndpoint .GetEndpointId () ); err != nil {
158157 return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
159158 }
160159
@@ -184,18 +183,21 @@ func splitAtlasPrivatelinkEndpointServiceDataFederationOnlineArchive(id string)
184183 return
185184}
186185
187- func newPrivateLinkEndpointDataLake (d * schema.ResourceData ) * matlas.PrivateLinkEndpointDataLake {
188- out := matlas.PrivateLinkEndpointDataLake {
189- EndpointID : d .Get ("endpoint_id" ).(string ),
190- Type : endpointType ,
186+ func newPrivateNetworkEndpointIDEntry (d * schema.ResourceData ) * admin.PrivateNetworkEndpointIdEntry {
187+ endpointType := endpointType
188+ out := admin.PrivateNetworkEndpointIdEntry {
189+ EndpointId : d .Get ("endpoint_id" ).(string ),
190+ Type : & endpointType ,
191191 }
192192
193193 if v , ok := d .GetOk ("comment" ); ok {
194- out .Comment = v .(string )
194+ comment := v .(string )
195+ out .Comment = & comment
195196 }
196197
197198 if v , ok := d .GetOk ("provider_name" ); ok && v != "" {
198- out .Provider = strings .ToUpper (v .(string ))
199+ providerName := strings .ToUpper (v .(string ))
200+ out .Provider = & providerName
199201 }
200202
201203 return & out
0 commit comments