I'd separate the HR import from the account actions. Have one part read and validate the CSV, then pass a normalized person record to functions for creating an account, updating attributes, and reconciling access. Put the department-to-role and role-to-group mappings in data rather than copying group logic into each workflow.
For a mover, calculate the groups the new role requires and compare them with the groups the automation is responsible for. Add the missing ones and remove obsolete managed ones. Keep a clear boundary around manually assigned or exceptional access so the script doesn't remove it by accident.
Start with a report or preview of the proposed changes, especially removals. Once the mappings and exceptions look right, you can decide whether to run it manually or schedule it.
m.731!zelvori:
That managed-group boundary matters. A department change doesn't necessarily explain every group a person belongs to, so exceptions need an owner and a way to review them.