Managing a resource with multiple states

I’m creating a resource in my provider that goes through several statuses: creating on the first Create API call, then some minutes later, it transitions into succeeded or failed.

I’m thinking what’s the best way to manage this kind of resource. Should I save it to state on the first apply with the status creating and then rely on subsequent apply/plan to trigger a Read that will update the state?

Or should I just poll for status on the first Create until the status becomes succeeded or failed. This option might introduce other issues like timeouts. And since creating a resource might than half an hour not sure it’s the best approach if I want to create 10s of resources.

Could also be a combination of both: poll for some time in the Create, then just save whatever the status I get into the state on timeout. And rely of later refreshes to update my resources.

I was wondering if there is a correct approach Terraform recommends.

I’d be inclined to stay in Create() until the new resource is available (or fails).

not sure it’s the best approach if I want to create 10s of resources

The parallelism option could help with that.

@hQnVyLRx

Thanks! This is my current implementation, but I wonder if a resource with the status “failed” is not still a resource that users should be able to remove with terraform destroy, for example. If I save only the successful ones, I will lose track of the failed ones.

You record the ID and surface the error.

On the next apply the failed resource will run your Delete() and Create() functions.