# OCI CLI small test

### 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`*&#x20;

I also nee&#x64;*:*

* [ an image OCID](https://docs.oracle.com/en-us/iaas/images/image/229363c7-b01f-4b71-8c19-0661df7e16b5/), 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,](https://isaac-exe.gitbook.io/various-tutorials/tutorials/install-and-configure-oci-cli#3-run-a-command-just-for-testing) 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:`

![](https://3964595292-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRFinYAjIA976nxMf0U%2F-MRpxpohtpIEwvgX7Jen%2F-MRpyJOIbsSWI9kuI9r9%2F20.png?alt=media\&token=3462326f-3cbc-4c40-b9bc-24c25d4d3a20)

`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:`

![](https://3964595292-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRFinYAjIA976nxMf0U%2F-MRpyQMIhOANKd6zpUk6%2F-MRpz9kLkXUzZIk1gMKO%2F21.png?alt=media\&token=a0e32453-c9bf-4ee4-abb9-6d32baf35333)

*`I can show the Public IP Address in this scenario, since I will be deleting this instance immediately.`*&#x20;
