OCI CLI small test
n.b: This is a continuation of "Create instance" and "Install and configure OCI CLI"
Preparation
Let's test our OCI CLI, and create another instance in the tenancy with oci cli, since we already know the Compartment OCID and Tenancy OCID.
Let's turn these OCIDs into environment variables, just in case:
root@deploymentmachine:~/.oci# export TENANCY="ocid1.tenancy.oc1..aaaaaasomefaketenancyidinhereaaaaa323423421"
root@deploymentmachine:~/.oci# export COMPARTMENT="ocid1.tenancy.oc1..aaaaaasomefakecompartmentidinhereaaaaa323423422"
root@deploymentmachine:~/.oci# export USER="ocid1.user.oc1..aaaaaasomefakeuseridinhereaaaaa323423423"
We would be needing Compartment only:
root@deploymentmachine:~/.oci# echo $COMPARTMENT
ocid1.tenancy.oc1..aaaaaasomefakecompartmentidinhereaaaaa323423422
I would also be needing a subnet OCID; since we are building this new instance in root compartment, we can use the subnet of our compartment:
root@deploymentmachine:~/.oci# oci compute instance list-vnics --compartment-id $COMPARTMENT | grep subnet
"subnet-id": "ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaafakesubnetidherehahaha1245",
No regular expression here for now, since we would just copy-paste the subnet OCID
I also need:
an image OCID, in my case, since I am located in "eu-frankfurt-1", I have chosen an image accordingly.
the path to my id_rsa.pub ssh key (now you understand why we had to create ssh keys on the cloud instance).
the availability domain - you can obtain it from our previous tutorial, by running command "oci iam availability-domain list"
the instance shape/size (in our case, we want to stick to free tier)
and a name (LinuxOCIcli)
Run script
Overall, the script (a bit hardcoded) would look as following:
#!/bin/bash
export INSTANCE_SIZE='VM.Standard.E2.1.Micro'
export INSTANCE_NAME='LinuxOCIcli'
export COMPARTMENT="ocid1.tenancy.oc1..aaaaaasomefakecompartmentidinhereaaaaa323423422"
oci compute instance launch \
-c ${COMPARTMENT} \
--shape "${INSTANCE_SIZE}" \
--display-name "${INSTANCE_NAME}" \
--image-id ocid1.image.oc1.eu-frankfurt-1.aaaaaaaahxue6crkdeevk75bzw63cmhh3c4uyqddcwov7mwlv7na4lkz7zla \
--ssh-authorized-keys-file "/root/.ssh/id_rsaf.pub" \
--subnet-id ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaafakesubnetidherehahaha1245 \
--availability-domain "Aodz:EU-FRANKFURT-1-AD-1" \
--wait-for-state RUNNING \
--raw-output
Make it executable, and run it:
root@deploymentmachine:~/.oci# chmod +x run.sh
root@deploymentmachine:~/.oci# ./run.sh
Action completed. Waiting until the resource has entered state: ('RUNNING',)
Let's check in the Oracle Cloud UI:

As soon as the instance is available and running, your script should provide a long output with all the details related to this new instance.
Once the instance LinuxOCIcli is available, let's ssh into it:

I can show the Public IP Address in this scenario, since I will be deleting this instance immediately.
Last updated