I am writing a provider using terraform plugin framework.
Every create / update operation in our system is eventually consistent - so I am running into trouble when writing acceptant testing: The create succeeded, but when trying to delete the server returns error as it thinks the resource does not exists. Adding a delay will give the system enough time so the resource will be actually created - or polling, trying to read the resource until it exists.
How can I do something like that inside the acceptance tests framework?
Hi @omerlh1,
If your system is not immediately read after write consistent then that’s something you will need to deal with in your main provider code, rather than in your acceptance tests: a provider should not return that it has successfully created an object unless it’s immediately possible to use that object for other operations.
Existing providers have used some different strategies for this depending on what the remote system is able to guarantee. The last resort for a system that offers no explicit signal of completion would be to politely poll the read endpoint until it returns successfully inside the main provider action.
For example, if a Create
call can’t be sure that the API call to create the object was sufficient for a subsequent read to immediately succeed then the Create
function itself should take some action like polling until the object has become reliably readable at least to this particular client. (Some APIs have localized consistency where an object can be readable when requested from one location but not yet readable in another, which is a particularly hairy case and hopefully not true for you.)
If you get this behavior right in your main provider code then the acceptance tests should “just work”, because they will wait for the main provider code to report the operation is fully complete before continuing.