@@ -254,16 +254,6 @@ func (r *databaseUserRS) Read(ctx context.Context, req resource.ReadRequest, res
254
254
username := state .Username .ValueString ()
255
255
projectID := state .ProjectID .ValueString ()
256
256
authDatabaseName := state .AuthDatabaseName .ValueString ()
257
-
258
- // Use the ID only with the IMPORT operation
259
- if state .ID .ValueString () != "" && (username == "" || projectID == "" || authDatabaseName == "" ) {
260
- projectID , username , authDatabaseName , err = SplitDatabaseUserImportID (state .ID .ValueString ())
261
- if err != nil {
262
- resp .Diagnostics .AddError ("error splitting database User info from ID" , err .Error ())
263
- return
264
- }
265
- }
266
-
267
257
connV2 := r .Client .AtlasV2
268
258
dbUser , httpResponse , err := connV2 .DatabaseUsersApi .GetDatabaseUser (ctx , projectID , authDatabaseName , username ).Execute ()
269
259
if err != nil {
@@ -347,7 +337,14 @@ func (r *databaseUserRS) Delete(ctx context.Context, req resource.DeleteRequest,
347
337
}
348
338
349
339
func (r * databaseUserRS ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
350
- resource .ImportStatePassthroughID (ctx , path .Root ("id" ), req , resp )
340
+ projectID , username , authDatabaseName , err := SplitDatabaseUserImportID (req .ID )
341
+ if err != nil {
342
+ resp .Diagnostics .AddError ("error splitting database User info from ID" , err .Error ())
343
+ return
344
+ }
345
+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("project_id" ), projectID )... )
346
+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("username" ), username )... )
347
+ resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("auth_database_name" ), authDatabaseName )... )
351
348
}
352
349
353
350
func SplitDatabaseUserImportID (id string ) (projectID , username , authDatabaseName string , err error ) {
0 commit comments