I’m trying to use the API to create a droplet that has attached block storage.
In the web interface you can create a volume directly in the “new droplet” interface. However this doesn’t appear to be the case with the API. That’s fine. I first create the block volume with the Block Storage API. Then I create a droplet.
When I create the droplet however, the VM is automatically powered on. This means that I have to poll the action to see when the VM has been created, then force it to power down, attach the block storage, then power it back up. This seems like a kind of ugly way to get the storage attached. Plus, I’m using cloud-init to automate running a task in the VM, and if the VM is already powered on and I power it off, it could mess up the cloud-init flow (e.g. on the second boot a script may not run).
The API docs do not indicate any parameters that can be used to include a block volume in the create endpoint, nor do I see any parameters to create the droplet without powering it on.
What’s the best practice for doing this via the API?
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.