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.
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.
Create this quite simple script in your home folder and replace items in the inst_array with your instance OCIDs:
Now you can stop all VMs with the single command and save a few dollars.