I have a realm on a server and I have configured this realm to my requirements. Now I want to copy this realm on the same server. I klick on “Export” and a JSON file is created. I change the realm name in the file and remove all ids in the file to not get duplicate key exception and then I Import the file again. It works.
My question:
Is there any easier way to export and import realms on the same server?
Is it ok to manipulate the JSON file manually. Are there any pitfalls? What else do I have to modify in the JSON file to not run into trouble?
It has been a while since there is no activity in this thread. But I am trying to follow the instructions above and keycloak gives me error “Could not create realm Conflict detected. See logs for details”.
I used the docker version and the problem is easy to replicate:
Create a realm.
Create a client.
In Realm settings, do a partial export including everything.
Edit the exported file to remove all Id’s (left empty).
Two variants from here:
Create a new realm using the exported file. → gives the error above
Create a new realm and do a “partial” import using the edited exported file → gives a 500 error
I just want to copy / paste the structure of a realm to do multitenancy with identical realms, having the same clients, groups, policies, roles, etc, but different users in each realm. But I can’t find how to do that.
Dont’t know if it helps I not only replace the ids with this regex:
“id”: “(.+?)”,
I also replace the internal id:
“internalId”: “(.+?)”,
This is the id of an exported IDP.
Also replace all occurences of the realm name
Thank you.
Managed to get it working for very simple realm templates. But as soon as I added client scopes or resources to a client, it failed.
I have not found a way to import complex realm structures with no users, that include roles, groups, clients, client scopes, client resources, policies, permissions, etc.
Since there is no problem to do it manually, I can always use RPA tools to automatise the creating of new realms, thought it would have been much nicer to do it from a template.