How do I use the API to deploy an Image and Resize at the same time?

Linode Staff

I am looking to deploy from an image and resize my Linode at the same time. Is there a way we can check if an instance is busy or not, from what I can see the "linode-cli linodes view" only states if offline/online, we're trying to set up a provisioning script and before resizing the disk of the instance we need to make sure that the instance is NOT busy or the resize fails obviously with the message: Linode busy.

2 Replies

While there is no way to tell the CLI to wait until your Linode has finished being created, it is able to report that data back to a script, which then waits to run the resize command until the Linode is ready. The following is an example script:

#!/usr/bin/env bash

## Create a Linode, but don't boot it yet...
LABEL=<Linode Label>
LINODE_ID="$(linode-cli linodes create --text \
                          --label "$LABEL" \
              --root_pass <root pass> \
              --region "us-east" \
              --type "g6-nanode-1" \
              --image <image name> \
              --booted false | grep "\b$LABEL\b" | awk '{print $1}'
)"

## Check to see if the new Linode is finished being created...
while [[ "$(linode-cli linodes list --text | grep "\b${LABEL}\b" | grep '\bprovisioning')" ]]; do
    sleep 1
done

sleep 3m
## Get the Disk to be resized's ID
DISK_ID="$(linode-cli linodes disks-list --text $LINODE_ID | awk '/VPS-IMAGE-01/{print $1}')"
echo "$LABEL"
echo "$LINODE_ID"
echo "$DISK_ID"

## Resize the Linode
linode-cli linodes disk-resize "$LINODE_ID" "$DISK_ID" --size "20200"

Use terraform, it should support what you want, you can define sizes of disks etc when it creates instance.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct