DEV Community

Cover image for An introduction to OCI CLI
Faris Durrani
Faris Durrani

Posted on • Updated on

An introduction to OCI CLI

Using Oracle Cloud's CLI to manage OCI resources

You probably are aware of the Oracle Cloud console, which is the online web interface on cloud.oracle.com that lets you create and manage resources on the Oracle Cloud Infrastructure through the GUI.

But let's say we want a standardized, predictable way of managing those resources. You know precisely the CPU and memory capacity of a Compute Instance that you want to deploy, along with its other details, and you want to describe that deployment to someone else.

Meet the OCI command line interface (CLI).

Screenshot - OCI CLI in action querying all regions

What is the CLI?

The CLI is a small-footprint tool that you can use on its own or with the Console to complete Oracle Cloud Infrastructure tasks. The CLI provides the same core functionality as the Console, plus additional commands. Some of these, such as the ability to run scripts, extend Console functionality. (Oracle)

Installing the CLI

These steps are specific to Mac. If you're on another OS, please check out the official Quickstart.

1. Installing using Homebrew

On Mac, you can install the CLI using Homebrew:



brew install oci-cli


Enter fullscreen mode Exit fullscreen mode

Verify installation using oci -v.

2. Set up the OCI Configuration using API Keys

Follow the steps in Setting up the OCI Configuration File using API Keys

3. Verify

Try:



oci iam compartment list


Enter fullscreen mode Exit fullscreen mode

to show a list of all your compartments in your tenancy:

A list of all compartments through OCI CLI

And now you have the power of OCI CLI! If you need to find a command, simply Google it, e.g., oci cli create compartment.

More ways to use the CLI

Interactive mode

Use oci -i to use the interactive mode if you don't want to Google the right command. The tool will show all the possible keywords following the command

Example of using interactive mode

Generate JSON parameter inputs

Sometimes the input to the CLI can be a complex JSON type and you want to know the structure of the input. Use --generate-param-json-input to see the structure.

Or --generate-full-command-json-input to see all attributes' formats:

Examples using generate json inputs

Multiple profiles

If you have multiple profiles, you can select the profile you want to use using --profile MYPROFILE.

Here, we are creating a new compartment:



oci iam compartment create --compartment-id ocid1.compartment.oc1..aaaaaaaakbr7t5yqjirrmwm3yourparentocidhereeejfnkrebnklnfefer --name Compartment2 --description "new compartment" --profile PROFILE2


Enter fullscreen mode Exit fullscreen mode

Creating a new compartment on a different profile

New compartment:

New compartment created

If you leave out --profile PROFILE2, it will default to the [DEFAULT] profile.

Using a JSON file input

To create a new Identity Domain, let's create a new JSON file called myFile.json:



{
    "compartment_id": "ocid1.tenancy.oc1..aaaaaaaashf677bcolbea4yblgu5jgyourcompartmentocidherefendskjjkewndsjkn",
    "description": "test identity domain",
    "display_name": "cli-id-december",
    "home_region" : "us-ashburn-1",
    "license_type" : "free"
}


Enter fullscreen mode Exit fullscreen mode

Run



oci iam domain create --from-json file://myFile.json


Enter fullscreen mode Exit fullscreen mode

Destroy a resource

Besides creating, the CLI can destroy deployed resources as well. For example:



oci iam compartment delete -c "ocid1.compartment.oc1..aaaaaaaagefmzdurtphobehgivez36nr3rq55wupta4bl4ljygcvaovxspia" --profile PROFILE2


Enter fullscreen mode Exit fullscreen mode

Deleting a compartment using CLI


More resources:

  1. Quickstart -- Installing the CLI
  2. Oracle Cloud Infrastructure CLI Command Reference

Safe harbor statement
The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.

This work is licensed under a Creative Commons Attribution 4.0 International License.

Top comments (0)