07/28/2023, 2:02 PM
Hello, I have a question about running Pulumi in Python — is there a way to ensure a particular resource type is only created one-at-a-time (i.e. through a mutex/lock)? I tried using the standard threading Python library, but this doesn’t seem to work, the requests are made concurrently. Also no luck with fasteners. ---- The context is — I have a custom DynamicProvider - I am writing a provider to be able to control the firewall setup of my cloud provider. Unfortunately, their API is pretty bad and the individual firewall entries do not have unique IDs, but use the index in the server list as their ID:
Copy code
Server XYZ
    [0] (A)
    [1] (B)
    [2] (C)
To delete a firewall entry, the request is
Copy code
DELETE /api/server/XYZ/firewall/0
The problem is that the delete operation has two steps: • GET request to determine what index the firewall rule I want to delete has • DELETE request of that index Pulumi seems to run the requests for resource creation in parallel. There is a race condition which can lead to incorrect behavior when I want to delete firewalls A, B from the example above:
Copy code
GET idx A -> 0
GET idx B -> 1
DELETE idx 0 -> deleted A
DELETE idx 1 -> deleted C (!!! - because the list is now just B,C)