In this post, Mariah McLaughlin, Software Engineer on the Vultr Cloud Native Team discusses the Vultr CLI, one of our open-source tools and shares how it can improve the way users manage their instances, storage, and more.
For Vultr users, navigating the members portal and using the v2 API to manage your services is a familiar process, but have you tried our Vultr CLI (command line interface)? Vultr CLI, our Go-powered open-source utility, allows you to effortlessly work with your instances, block storages, firewalls, and more – all from within your terminal. In just a few command line arguments, you can check region availability for bare metal servers, spin up a new instance with all the bells and whistles, or create a load balancer to distribute traffic to your poppin’ ecommerce site.
The CLI is designed with simplicity in mind, returning your data in a clean, readable format. You can see important information organized in one place. No need to copy, paste, and format API calls each time you want to interact with your resources. With the CLI, you can avoid cumbersome, repetitive typing, like this:
curl --location \
--request GET 'https://api.vultr.com/v2/account' \
--header 'Authorization: Bearer MYAPIKEY'
And retrieve your account information like this:
In this case, it’s a no-brainer to use the CLI. Even spinning up large resources is boiled down to a few arguments. So, when you opt for Vultr CLI, you won’t miss anything but extra clicks and keystrokes.
The best part is that it is powered by our v2 API, which introduced many new features like paging and increased rate limits to improve your experience. Below we explore how Vultr CLI can help you create some new resources:
Note: If you don’t already have a funded Vultr account, create one here. This demo will create a real instance and block storage which will accrue a small hourly charge. Remember to delete these resources to avoid extra charges.
Install the CLI using any of the methods shown here. Since I’m using MacOS, I will use brew as an example, though any of the methods mentioned in the documentation will work just fine. Vultr supplies precompiled binaries for your OS of choice.
brew tap vultr/vultr-cli
brew install vultr-cli
The CLI needs your API key to authenticate. For demo purposes, Linux and macOS users can set the key by either typing
export VULTR_API_KEY=your_api_key into your terminal, or for longer term, add it to your local environment so that you won't need to paste in your API key every time you start a new terminal session.
vultr-cli into the terminal to see a list of available commands. Give some a try! Below are a few simple, useful commands to see Vultr’s plans, os’s, and regions:
vultr-cli plans list
vultr-cli os list
vultr-cli regions list
As you explore, it’s okay to not yet know how to build up your commands; the CLI will guide you by pointing out required and optional flags, returning helpful error messages if something goes wrong along the way.
To get a glimpse of this, try creating an instance without any additional flags – don’t worry, you won’t be charged in this case:
vultr-cli instance create
The output returns an error message indicating required flags in addition to the many optional flags to customize your instance.
Now that you have a feel for the CLI, we will successfully create an instance with an attached block storage. Just like creating an instance through the members portal, you must choose a region, a plan, and one of the following: an operating system, application, or snapshot.
Create an Instance
Note: The following example will create an instance with a CentOS 8 operating system in New York/New Jersey ("ewr" is the airport code we use for this datacenter) that will cost $0.007/hr.
vultr-cli instance create --region ewr --plan vc2-1c-1gb \
--os 362 --label my-instance --ipv6 true
Take note of the instance’s ID, it is a required flag to attach the block storage.
Create a Block Storage, Attach to Instance
Note: The following example will create a 10 GB block storage in New Jersey that will cost $0.007/hr.
vultr-cli block-storage create --region ewr --size 10 --label my-bl0ck
Oops, that label name isn’t quite right. Use the block storage ID to update the label:
vultr-cli block-storage label block-storage-id --label my-block
Now, take the block storage ID and instance ID and apply it to the following command to attach your instance to the block storage:
vultr-cli block-storage attach block-storage-id --instance instance-id
Let’s confirm that the instance is actually attached to the block storage:
vultr-cli block-storage list
You should see the instance ID for your block storage in the response. Finally, let’s clean up our resources by deleting your instance and block storage:
vultr-cli block-storage delete block-storage-id
vultr-cli instance delete instance-id
So, when do I use the API?
Of course, you are welcome to use the API calls to interact with Vultr products. You can even write bash scripts to accomplish everything the API can do. The API excels when it’s integrated into your services and as the core component that powers our many open source tools.
What can’t the Vultr CLI do?
While the CLI can handle most of your day-to-day, there are several important reasons you will still need to access your members portal:
- API key management
- Creating and tracking your support ticket
- Limit increase requests
- Update password, personal information
- Update billing information
- Join our Trusted Author Program
Whether you’re a seasoned tech professional or just getting started, the Vultr CLI can greatly improve your workflow. While there are many ways to approach resource management, the CLI’s robust command set helps developers (and non-developers!) work more efficiently so they can keep working on the projects they love.
Explore Vultr's Open Source Tools
You'll find the Vultr CLI and the rest of Vultr's open-source tools in our actively maintained GitHub repositories. We have more offerings planned, so stay tuned!