8
8
"strings"
9
9
"time"
10
10
11
- matlas "go.mongodb.org/atlas/mongodbatlas "
11
+ "go.mongodb.org/atlas-sdk/v20231115005/admin "
12
12
13
13
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
14
14
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -26,11 +26,11 @@ const (
26
26
27
27
func Resource () * schema.Resource {
28
28
return & schema.Resource {
29
- CreateContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveCreate ,
30
- ReadContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveRead ,
31
- DeleteContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveDelete ,
29
+ CreateContext : resourceCreate ,
30
+ ReadContext : resourceRead ,
31
+ DeleteContext : resourceDelete ,
32
32
Importer : & schema.ResourceImporter {
33
- StateContext : resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveImportState ,
33
+ StateContext : resourceImport ,
34
34
},
35
35
Schema : map [string ]* schema.Schema {
36
36
"project_id" : {
@@ -65,12 +65,12 @@ func Resource() *schema.Resource {
65
65
}
66
66
}
67
67
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
70
70
projectID := d .Get ("project_id" ).(string )
71
71
endpointID := d .Get ("endpoint_id" ).(string )
72
72
73
- _ , _ , err := conn . DataLakes . CreatePrivateLinkEndpoint (ctx , projectID , newPrivateLinkEndpointDataLake (d ))
73
+ _ , _ , err := connV2 . DataFederationApi . CreateDataFederationPrivateEndpoint (ctx , projectID , newPrivateNetworkEndpointIDEntry (d )). Execute ( )
74
74
if err != nil {
75
75
return diag .FromErr (fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveCreate , projectID , err ))
76
76
}
@@ -80,47 +80,46 @@ func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveCr
80
80
"endpoint_id" : endpointID ,
81
81
}))
82
82
83
- return resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveRead (ctx , d , meta )
83
+ return resourceRead (ctx , d , meta )
84
84
}
85
85
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
88
88
ids := conversion .DecodeStateID (d .Id ())
89
89
projectID := ids ["project_id" ]
90
90
endopointID := ids ["endpoint_id" ]
91
91
92
- privateEndpoint , resp , err := conn . DataLakes . GetPrivateLinkEndpoint ( context . Background () , projectID , endopointID )
92
+ privateEndpoint , resp , err := connV2 . DataFederationApi . GetDataFederationPrivateEndpoint ( ctx , projectID , endopointID ). Execute ( )
93
93
if err != nil {
94
94
if resp != nil && resp .StatusCode == http .StatusNotFound {
95
95
d .SetId ("" )
96
96
return nil
97
97
}
98
-
99
98
return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
100
99
}
101
100
102
- if err := d .Set ("comment" , privateEndpoint .Comment ); err != nil {
101
+ if err := d .Set ("comment" , privateEndpoint .GetComment () ); err != nil {
103
102
return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
104
103
}
105
104
106
- if err := d .Set ("provider_name" , privateEndpoint .Provider ); err != nil {
105
+ if err := d .Set ("provider_name" , privateEndpoint .GetProvider () ); err != nil {
107
106
return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
108
107
}
109
108
110
- if err := d .Set ("type" , privateEndpoint .Type ); err != nil {
109
+ if err := d .Set ("type" , privateEndpoint .GetType () ); err != nil {
111
110
return diag .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveRead , endopointID , projectID , err )
112
111
}
113
112
114
113
return nil
115
114
}
116
115
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
119
118
ids := conversion .DecodeStateID (d .Id ())
120
119
projectID := ids ["project_id" ]
121
120
endpointID := ids ["endpoint_id" ]
122
121
123
- _ , err := conn . DataLakes . DeletePrivateLinkEndpoint (ctx , projectID , endpointID )
122
+ _ , _ , err := connV2 . DataFederationApi . DeleteDataFederationPrivateEndpoint (ctx , projectID , endpointID ). Execute ( )
124
123
if err != nil {
125
124
return diag .FromErr (fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveDelete , endpointID , projectID , err ))
126
125
}
@@ -130,31 +129,31 @@ func resourceMongoDBAtlasPrivatelinkEndpointServiceDataFederationOnlineArchiveDe
130
129
return nil
131
130
}
132
131
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
135
134
projectID , endpointID , err := splitAtlasPrivatelinkEndpointServiceDataFederationOnlineArchive (d .Id ())
136
135
if err != nil {
137
136
return nil , err
138
137
}
139
138
140
- privateEndpoint , _ , err := conn . DataLakes . GetPrivateLinkEndpoint (ctx , projectID , endpointID )
139
+ privateEndpoint , _ , err := connV2 . DataFederationApi . GetDataFederationPrivateEndpoint (ctx , projectID , endpointID ). Execute ( )
141
140
if err != nil {
142
141
return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
143
142
}
144
143
145
- if err := d .Set ("comment" , privateEndpoint .Comment ); err != nil {
144
+ if err := d .Set ("comment" , privateEndpoint .GetComment () ); err != nil {
146
145
return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
147
146
}
148
147
149
- if err := d .Set ("provider_name" , privateEndpoint .Provider ); err != nil {
148
+ if err := d .Set ("provider_name" , privateEndpoint .GetProvider () ); err != nil {
150
149
return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
151
150
}
152
151
153
- if err := d .Set ("type" , privateEndpoint .Type ); err != nil {
152
+ if err := d .Set ("type" , privateEndpoint .GetType () ); err != nil {
154
153
return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
155
154
}
156
155
157
- if err := d .Set ("endpoint_id" , privateEndpoint .EndpointID ); err != nil {
156
+ if err := d .Set ("endpoint_id" , privateEndpoint .GetEndpointId () ); err != nil {
158
157
return nil , fmt .Errorf (errorPrivateEndpointServiceDataFederationOnlineArchiveImport , endpointID , projectID , err )
159
158
}
160
159
@@ -184,18 +183,21 @@ func splitAtlasPrivatelinkEndpointServiceDataFederationOnlineArchive(id string)
184
183
return
185
184
}
186
185
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 ,
191
191
}
192
192
193
193
if v , ok := d .GetOk ("comment" ); ok {
194
- out .Comment = v .(string )
194
+ comment := v .(string )
195
+ out .Comment = & comment
195
196
}
196
197
197
198
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
199
201
}
200
202
201
203
return & out
0 commit comments