Don’t want to spend time trying to find the compartment ID in OCI CLI? Jq to the rescue!

If you’re using OCI CLI, you probably have realized compartment ID is a big thing. It’s needed in many of the commands, and sometimes it’s a pain to go find the compartment you’re looking for if you have many compartments.

Jq is the solution here, just like it’s the solution the almost every CLI related problem in the world.

Here’s a little helper function that will print the ID of the compartment name you passed as a parameter:

function fcid() {
oci iam compartment list --all | jq -r ".[] | .[] | select(.name==\"$@\") | .id"
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s