Skip to content

Commit e860fa9

Browse files
committed
move importID split to ImportState function
1 parent 27168d9 commit e860fa9

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

internal/service/databaseuser/resource_database_user.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,6 @@ func (r *databaseUserRS) Read(ctx context.Context, req resource.ReadRequest, res
254254
username := state.Username.ValueString()
255255
projectID := state.ProjectID.ValueString()
256256
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-
267257
connV2 := r.Client.AtlasV2
268258
dbUser, httpResponse, err := connV2.DatabaseUsersApi.GetDatabaseUser(ctx, projectID, authDatabaseName, username).Execute()
269259
if err != nil {
@@ -347,7 +337,14 @@ func (r *databaseUserRS) Delete(ctx context.Context, req resource.DeleteRequest,
347337
}
348338

349339
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)...)
351348
}
352349

353350
func SplitDatabaseUserImportID(id string) (projectID, username, authDatabaseName string, err error) {

0 commit comments

Comments
 (0)