Is there a built-in method to make droplet creation idempotent? For example, if you run this command to create a droplet twice…
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"name":"example.com","region":"nyc3","size":"s-1vcpu-1gb","image":"ubuntu-20-04-x64","ssh_keys":[289794,"3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45"],"backups":true,"ipv6":true,"monitoring":true,"tags":["env:prod","web"],"user_data":"#cloud-config\nruncmd:\n - touch /test.txt\n","vpc_uuid":"760e09ef-dc84-11e8-981e-3cfdfeaae000"}' \
"https://api.digitalocean.com/v2/droplets"
…two droplets will be created. Is there an option to run the command twice, and prevent a second droplet from being created?
If the answer is yes, how does one accomplish this? If the answer is no, is there a recommended approach to implement droplet uniqueness?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey @amorphid,
I believe that this is not available as of the time being via the DigitalOcean API.
The best thing to do to get your voice heard regarding this would be to head over to our Product Ideas board and post a new idea, including as much information as possible for what you’d like to see implemented.
But in the meantime, what you could do is to use the ‘List All Droplets’ API endpoint and check if a Droplet with the specific name already exists.
Here is a quick script as an example:
Alternatively, you could use the
doctl
CLI and build a similar script as well.Hope that helps!
- Bobby.