Terraform - Error Handling


I’m opening this case with the community to help me.

I’m creating an automation for creating users, groups and roles in Keycloak using Terraform.

Explaining the situation: When trying to create a user that already exists before, it ends up showing the error below:

That is, I simulated the creation of a user that already existed and took the error. I would like to know if there is any way to handle a terraform error in the following situation:

If I run task X and I get error Y does it run module XY? If yes, how would you do it?

Thank you very much