@@ -15,7 +15,7 @@ import (
15
15
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
16
16
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
17
17
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
18
- matlas "go.mongodb.org/atlas/mongodbatlas "
18
+ "go.mongodb.org/atlas-sdk/v20231115005/admin "
19
19
)
20
20
21
21
const (
@@ -27,11 +27,11 @@ const (
27
27
28
28
func Resource () * schema.Resource {
29
29
return & schema.Resource {
30
- CreateContext : resourceMongoDBAtlasPrivateLinkEndpointCreate ,
31
- ReadContext : resourceMongoDBAtlasPrivateLinkEndpointRead ,
32
- DeleteContext : resourceMongoDBAtlasPrivateLinkEndpointDelete ,
30
+ CreateContext : resourceCreate ,
31
+ ReadContext : resourceRead ,
32
+ DeleteContext : resourceDelete ,
33
33
Importer : & schema.ResourceImporter {
34
- StateContext : resourceMongoDBAtlasPrivateLinkEndpointImportState ,
34
+ StateContext : resourceImport ,
35
35
},
36
36
Schema : map [string ]* schema.Schema {
37
37
"project_id" : {
@@ -114,26 +114,26 @@ func Resource() *schema.Resource {
114
114
}
115
115
}
116
116
117
- func resourceMongoDBAtlasPrivateLinkEndpointCreate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
118
- conn := meta .(* config.MongoDBClient ).Atlas
117
+ func resourceCreate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
118
+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
119
119
projectID := d .Get ("project_id" ).(string )
120
120
providerName := d .Get ("provider_name" ).(string )
121
121
region := d .Get ("region" ).(string )
122
122
123
- request := & matlas. PrivateEndpointConnection {
123
+ request := & admin. CloudProviderEndpointServiceRequest {
124
124
ProviderName : providerName ,
125
125
Region : region ,
126
126
}
127
127
128
- privateEndpointConn , _ , err := conn . PrivateEndpoints . Create (ctx , projectID , request )
128
+ privateEndpoint , _ , err := connV2 . PrivateEndpointServicesApi . CreatePrivateEndpointService (ctx , projectID , request ). Execute ( )
129
129
if err != nil {
130
130
return diag .FromErr (fmt .Errorf (errorPrivateLinkEndpointsCreate , err ))
131
131
}
132
132
133
133
stateConf := & retry.StateChangeConf {
134
134
Pending : []string {"INITIATING" , "DELETING" },
135
135
Target : []string {"WAITING_FOR_USER" , "FAILED" , "DELETED" , "AVAILABLE" },
136
- Refresh : resourcePrivateLinkEndpointRefreshFunc (ctx , conn , projectID , providerName , privateEndpointConn . ID ),
136
+ Refresh : refreshFunc (ctx , connV2 , projectID , providerName , privateEndpoint . GetId () ),
137
137
Timeout : d .Timeout (schema .TimeoutCreate ),
138
138
MinTimeout : 5 * time .Second ,
139
139
Delay : 3 * time .Second ,
@@ -146,25 +146,25 @@ func resourceMongoDBAtlasPrivateLinkEndpointCreate(ctx context.Context, d *schem
146
146
}
147
147
148
148
d .SetId (conversion .EncodeStateID (map [string ]string {
149
- "private_link_id" : privateEndpointConn . ID ,
149
+ "private_link_id" : privateEndpoint . GetId () ,
150
150
"project_id" : projectID ,
151
151
"provider_name" : providerName ,
152
152
"region" : region ,
153
153
}))
154
154
155
- return resourceMongoDBAtlasPrivateLinkEndpointRead (ctx , d , meta )
155
+ return resourceRead (ctx , d , meta )
156
156
}
157
157
158
- func resourceMongoDBAtlasPrivateLinkEndpointRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
159
- conn := meta .(* config.MongoDBClient ).Atlas
158
+ func resourceRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
159
+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
160
160
161
161
ids := conversion .DecodeStateID (d .Id ())
162
162
projectID := ids ["project_id" ]
163
163
privateLinkID := ids ["private_link_id" ]
164
164
providerName := ids ["provider_name" ]
165
165
region := ids ["region" ]
166
166
167
- privateEndpoint , resp , err := conn . PrivateEndpoints . Get (context .Background (), projectID , providerName , privateLinkID )
167
+ privateEndpoint , resp , err := connV2 . PrivateEndpointServicesApi . GetPrivateEndpointService (context .Background (), projectID , providerName , privateLinkID ). Execute ( )
168
168
if err != nil {
169
169
if resp != nil && resp .StatusCode == http .StatusNotFound {
170
170
d .SetId ("" )
@@ -174,35 +174,35 @@ func resourceMongoDBAtlasPrivateLinkEndpointRead(ctx context.Context, d *schema.
174
174
return diag .FromErr (fmt .Errorf (errorPrivateLinkEndpointsRead , privateLinkID , err ))
175
175
}
176
176
177
- if err := d .Set ("private_link_id" , privateEndpoint .ID ); err != nil {
177
+ if err := d .Set ("private_link_id" , privateEndpoint .GetId () ); err != nil {
178
178
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "private_link_id" , privateLinkID , err ))
179
179
}
180
180
181
- if err := d .Set ("endpoint_service_name" , privateEndpoint .EndpointServiceName ); err != nil {
181
+ if err := d .Set ("endpoint_service_name" , privateEndpoint .GetEndpointServiceName () ); err != nil {
182
182
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "endpoint_service_name" , privateLinkID , err ))
183
183
}
184
184
185
- if err := d .Set ("error_message" , privateEndpoint .ErrorMessage ); err != nil {
185
+ if err := d .Set ("error_message" , privateEndpoint .GetErrorMessage () ); err != nil {
186
186
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "error_message" , privateLinkID , err ))
187
187
}
188
188
189
- if err := d .Set ("interface_endpoints" , privateEndpoint .InterfaceEndpoints ); err != nil {
189
+ if err := d .Set ("interface_endpoints" , privateEndpoint .GetInterfaceEndpoints () ); err != nil {
190
190
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "interface_endpoints" , privateLinkID , err ))
191
191
}
192
192
193
- if err := d .Set ("private_endpoints" , privateEndpoint .PrivateEndpoints ); err != nil {
193
+ if err := d .Set ("private_endpoints" , privateEndpoint .GetPrivateEndpoints () ); err != nil {
194
194
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "interface_endpoints" , privateLinkID , err ))
195
195
}
196
196
197
- if err := d .Set ("private_link_service_name" , privateEndpoint .PrivateLinkServiceName ); err != nil {
197
+ if err := d .Set ("private_link_service_name" , privateEndpoint .GetPrivateLinkServiceName () ); err != nil {
198
198
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "interface_endpoints" , privateLinkID , err ))
199
199
}
200
200
201
- if err := d .Set ("private_link_service_resource_id" , privateEndpoint .PrivateLinkServiceResourceID ); err != nil {
201
+ if err := d .Set ("private_link_service_resource_id" , privateEndpoint .GetPrivateLinkServiceResourceId () ); err != nil {
202
202
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "interface_endpoints" , privateLinkID , err ))
203
203
}
204
204
205
- if err := d .Set ("status" , privateEndpoint .Status ); err != nil {
205
+ if err := d .Set ("status" , privateEndpoint .GetStatus () ); err != nil {
206
206
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "status" , privateLinkID , err ))
207
207
}
208
208
@@ -214,32 +214,32 @@ func resourceMongoDBAtlasPrivateLinkEndpointRead(ctx context.Context, d *schema.
214
214
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "region" , privateLinkID , err ))
215
215
}
216
216
217
- if err := d .Set ("endpoint_group_names" , privateEndpoint .EndpointGroupNames ); err != nil {
217
+ if err := d .Set ("endpoint_group_names" , privateEndpoint .GetEndpointGroupNames () ); err != nil {
218
218
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "endpoint_group_names" , privateLinkID , err ))
219
219
}
220
220
221
- if err := d .Set ("region_name" , privateEndpoint .RegionName ); err != nil {
221
+ if err := d .Set ("region_name" , privateEndpoint .GetRegionName () ); err != nil {
222
222
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "region_name" , privateLinkID , err ))
223
223
}
224
224
225
- if err := d .Set ("service_attachment_names" , privateEndpoint .ServiceAttachmentNames ); err != nil {
225
+ if err := d .Set ("service_attachment_names" , privateEndpoint .GetServiceAttachmentNames () ); err != nil {
226
226
return diag .FromErr (fmt .Errorf (ErrorPrivateLinkEndpointsSetting , "service_attachment_names" , privateLinkID , err ))
227
227
}
228
228
229
229
return nil
230
230
}
231
231
232
- func resourceMongoDBAtlasPrivateLinkEndpointDelete (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
233
- conn := meta .(* config.MongoDBClient ).Atlas
232
+ func resourceDelete (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
233
+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
234
234
235
235
ids := conversion .DecodeStateID (d .Id ())
236
236
privateLinkID := ids ["private_link_id" ]
237
237
projectID := ids ["project_id" ]
238
238
providerName := ids ["provider_name" ]
239
239
240
- resp , err := conn . PrivateEndpoints . Delete (ctx , projectID , providerName , privateLinkID )
240
+ _ , resp , err := connV2 . PrivateEndpointServicesApi . DeletePrivateEndpointService (ctx , projectID , providerName , privateLinkID ). Execute ( )
241
241
if err != nil {
242
- if resp .Response . StatusCode == 404 {
242
+ if resp .StatusCode == 404 {
243
243
return nil
244
244
}
245
245
@@ -251,7 +251,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointDelete(ctx context.Context, d *schem
251
251
stateConf := & retry.StateChangeConf {
252
252
Pending : []string {"DELETING" },
253
253
Target : []string {"DELETED" , "FAILED" },
254
- Refresh : resourcePrivateLinkEndpointRefreshFunc (ctx , conn , projectID , providerName , privateLinkID ),
254
+ Refresh : refreshFunc (ctx , connV2 , projectID , providerName , privateLinkID ),
255
255
Timeout : d .Timeout (schema .TimeoutDelete ),
256
256
MinTimeout : 5 * time .Second ,
257
257
Delay : 3 * time .Second ,
@@ -265,7 +265,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointDelete(ctx context.Context, d *schem
265
265
return nil
266
266
}
267
267
268
- func resourceMongoDBAtlasPrivateLinkEndpointImportState (ctx context.Context , d * schema.ResourceData , meta any ) ([]* schema.ResourceData , error ) {
268
+ func resourceImport (ctx context.Context , d * schema.ResourceData , meta any ) ([]* schema.ResourceData , error ) {
269
269
conn := meta .(* config.MongoDBClient ).Atlas
270
270
271
271
parts := strings .Split (d .Id (), "-" )
@@ -304,21 +304,26 @@ func resourceMongoDBAtlasPrivateLinkEndpointImportState(ctx context.Context, d *
304
304
return []* schema.ResourceData {d }, nil
305
305
}
306
306
307
- func resourcePrivateLinkEndpointRefreshFunc (ctx context.Context , client * matlas. Client , projectID , providerName , privateLinkID string ) retry.StateRefreshFunc {
307
+ func refreshFunc (ctx context.Context , client * admin. APIClient , projectID , providerName , privateLinkID string ) retry.StateRefreshFunc {
308
308
return func () (any , string , error ) {
309
- p , resp , err := client .PrivateEndpoints . Get (ctx , projectID , providerName , privateLinkID )
309
+ p , resp , err := client .PrivateEndpointServicesApi . GetPrivateEndpointService (ctx , projectID , providerName , privateLinkID ). Execute ( )
310
310
if err != nil {
311
- if resp .Response . StatusCode == 404 {
311
+ if resp .StatusCode == 404 {
312
312
return "" , "DELETED" , nil
313
313
}
314
314
315
315
return nil , "REJECTED" , err
316
316
}
317
317
318
- if p .Status != "WAITING_FOR_USER" {
319
- return "" , p .Status , nil
318
+ status := ""
319
+ if _ , ok := p .GetStatusOk (); ok {
320
+ status = p .GetStatus ()
321
+ }
322
+
323
+ if status != "WAITING_FOR_USER" {
324
+ return "" , status , nil
320
325
}
321
326
322
- return p , p . Status , nil
327
+ return p , status , nil
323
328
}
324
329
}
0 commit comments