How Oracle Cloud helps you save on Oracle Cloud

The recent Ahmed's post on OCI client installation gave me an idea to post this piece. My Oracle Cloud trial has ended, and I have no other option but to be more budget aware. The most apparent recipe is quite similar to the basic household rule: "Turn the lights off when you leave the room."

It's obvious and easy sounded task could be a quite annoying task in Oracle Cloud. Even for my small OCI footprint, I have to jump between several compartments to select instances and change states. The automation of the dull tasks is the right answer, and what I like about Oracle Cloud, you don't need to have any additional clients, terminals, or any of that such if your region has Oracle Cloud Shell enabled.

Check if you have this icon on your OCI page

The Cloud Shell precisely fits my case. It's a small (about 5Gb) Linux Shell environment with the preconfigured OCI tools and clients. All you need to do is to configure your command line and create automation scripts. I have used OCI SDK documentation as the main reference, but you may find plenty of articles about CLI configuration.

Screen shows you the result of OCI SDK configuration.

Create this quite simple script in your home folder and replace items in the inst_array with your instance OCIDs:

#!/bin/sh
# List of instances you want to manage as a group
inst_array=(ocid1.instance.oc1.iad.abcde.1 ocid1.instance.oc1.iad.abcde.2 ocid1.instance.oc1.iad.abcde3)
for inst in "${inst_array[@]}"; do
oci compute instance action --action ${1^^} --instance-id ${inst}
done
My name for this script is all-oci-vms.sh

Now you can stop all VMs  with the single command and save a few dollars.

michael_mi@cloudshell:~ (us-ashburn-1)$ bin/all-oci-vms.sh stop
or start them with the start argument