Get your Tenancy OCID using a single oci-cli command

If you need to get your Tenancy OCID to use in some of your scripts, there is no simple oci-cli command that will do it for you.

However, using some parameters you can get the raw output:

$ oci iam compartment list \
--all \
--compartment-id-in-subtree true \
--access-level ACCESSIBLE \
--include-root \
--raw-output \
--query "data[?contains(\"id\",'tenancy')].id | [0]"
ocid1.tenancy.oc1..aaaaaaaaunn73emggesayznwlqeunvmbsmbtgzbigdxxxxxxxxxxxxxxxxxx

That's it. As it took my a couple of minutes to write this single command, thought that someone could be looking for a similar solution.

Have you enjoyed? Please leave a comment or give a 👍!

1 comments

    • KK on February 8, 2023 at 08:18
    • Reply

    `
    $ oci iam compartment list --raw-output --query "data[?contains(\"compartment-id\",'.tenancy.')].\"compartment-id\" | [0]"
    `

Leave a Reply

Your email address will not be published.