Best Practice for handling asynchronous operations in Terraform Resources

I have a Terraform resource that includes asynchronous REST APIs. The REST API returns the job ID. There is another REST API to track job status. The time taken to complete the job depends on the size of the data (The smaller the size of the data, the faster the job is completed).

Please suggest ways to design a Terraform solution for such kind of resource.

Terraform requires that the ApplyResourceChange call run synchronously, because its return signals to dependent resources that the action is complete. Since there’s a callback available to track the status, it sounds like the resource has everything needed already, you just need to use the callback to track when the job has completed. It’s not uncommon that you have to resort to polling in many APIs to get the result as soon as possible.

@jbardin Are you saying polling is the recommended option in such cases?

I’m saying if polling is the only option, then that is what you must use. If there another way to be notified of the job completion, then you can use that of course. What you can’t do is leave the resource in an unfinished state, because anything which depends on that resource will subsequently fail.

Thanks @jbardin. It will have impact on dependent resources.