Locking to avoid multiple like resources being created concurrently?

Due to API deficiency, one of my resources needs to diff a list of remote resources of its kind either side of create, in order to determine its own identity.

As a result, adding two new terraform resources of this type at the same time results in my ‘expected one but found two’ error. The error’s designed to guard against extra-terraform changes, but I can’t just remove and ignore the issue, since if the diff has size two I don’t know which to assign to the created (terraform) resource.

Is there any way of locking around resource CRUD functions, (specifically or provider-wide) to ensure that they’re not invoked for different resources concurrently?

2 Likes