I have started working on a collection for OCI (Oracle CLoud) platform.
During the design and planning I tackled an interesting point and I would be happy to consult this topic in this forum.
OCI doesn’t maintain unique resource names which means that a resource can be created over and over again with the same name and there is no issue with that. When a resource is created a resource/-id is being returned to the user. This ID can be used in order to update or delete that resource.
So full lifecycle scenario can be something like:
Create a resource using a name → fetch ID → call a task to update the resource using the resource id → delete the resource using the id.
This is reasonable and works fine. The issue I have with that and would be happy to discuss is that this approach breaks idempotency. A user calling the same creation task twice will result in the creation of 2 resources.
Is this approach makes sense as long as I document this behavior or do we expect it to be handled differently in such case?
You can always require the name to be unique from your side. In other words, you should test if the resource with the particular name already exists and use the existing resource to manage it instead of creating a new resource. You can even let the user choose the behavior.
In any case, documenting the behavior is essential.
I personally would go down the route of making the module/role idempotent even if it means workarounding the limitations of the OCI API or enforcing the uniqueness of names or other identifiers from your side. In the end, Ansible is all about the idempotency.
I thought I dealt with a similar issue awhile ago but I cant find it.
Generally I assume people will not read/miss the documentation. If a behavior seems really disruptive or risky, I would try to head it off in the module code and allow a user to “opt in” rather than “opt out”.
So id say, maybe raise an error if another resource with the same name existed and the ID was provided. And have a parameter so the user can ignore the error and create the object anyway?