Skip to content

Instantly share code, notes, and snippets.



Last active Feb 27, 2020
What would you like to do?
This script auto-configure your OCI Cloud Shell Fn CLI context.
# Last update : February, 2020
# Author:
# This script auto-configure your Fn CLI context on OCI Cloud Shell.
# 1. On OCI Console, create an OCIR repository named like your tenant
# 2. Then just run this one-liner at the Cloud Shell prompt:
# sh <( curl -L )
# Magic sauce is made of OCI IAM Instance Principal + OCI cli JMESPath integration and a glimpse of jq ;-)
# (oci raw-request parsing with JMESPath seems to not follow the standard. Forced here to use jq)
COMPARTMENT=$(oci iam availability-domain list --raw-output --query 'data[0]."compartment-id"')
REGION_NAME=$(oci iam region-subscription list --raw-output --query 'data[?"is-home-region"]."region-name" | [0]')
REGION_KEY=$(oci iam region-subscription list --raw-output --query 'data[?"is-home-region"]."region-key" | [0]' | tr '[:upper:]' '[:lower:]')
NAMESPACE=$(oci os ns get --query 'data' --raw-output)
CONTEXT=$(oci raw-request --http-method GET --target-uri https://identity.$$COMPARTMENT | jq -r '')
fn create context $CONTEXT --provider oracle-ip
fn use context $CONTEXT
fn update context oracle.compartment-id $COMPARTMENT
fn update context api-url https://functions.$
fn update context registry $$NAMESPACE/$REPO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment