Various Tutorials
  • About
  • Tutorials
    • 1. Instance for deployment
      • Create instance
      • Install and configure OCI CLI
      • OCI CLI small test
      • Install and configure Terraform
      • Terraform - small test
    • 2. OCI Networking &Terraform
      • 2.1 VCN (basics)
        • 2.1.1 Create a virtual network using Start VCN Wizard
        • 2.1.2 VCN & public subnet (step-by-step in Terraform)
        • 2.1.3 VCN & public subnet (new compartment)
        • 2.1.4 VCN, Terraform and Ansible (Nginx example)
        • 2.1.5 VCN & private subnet (step-by-step in Terraform)
      • 2.2
      • 2.3
    • 3. Untitled
    • 4. Untitled
    • 5. ATP and APEX
      • Setup Autonomous Database
        • Deploying ATP using OCI Interface
        • Deploy with OCI CLI
      • Setup APEX on ATP
      • Connect remotely to ATP
      • ATP, APEX and Jupyter
      • Demo
    • 6. MySQL
      • 6.1. The basics - OCI UI (MySQL DB System)
      • 6.2 The basics - OCI CLI (MySQL DB System)
      • 6.3 Access MySQL DB System
      • 6.4 HeatWave and MySQL DB Service
      • 6.5 Python SDK
      • 6.6 MySQL Replication (Compute Instances)
      • 6.7 Monitoring MySQL instances
        • Deploy MySQL instances
        • Monitoring tools
          • 1. Networking setup
          • 2. Prometheus setup
          • 3. MySQL Prometheus Exporter Setup
          • 4. Grafana setup
          • 5. Grafana metric graphs
    • 7. MySQL OCI &Terraform
      • 7.1 Deploy MySQL DB System with Terraform (basic tutorial)
      • 7.2 Deploy MySQL DB System with Terraform and access the system
      • 7.3 Endpoints
      • 7.4 Channels (troubleshooting)
        • Fixed MySQL source - MDS replication
      • 7.5 Channels (code)
Powered by GitBook
On this page
  • Preparation
  • Run script
  1. Tutorials
  2. 1. Instance for deployment

OCI CLI small test

n.b: This is a continuation of "Create instance" and "Install and configure OCI CLI"

PreviousInstall and configure OCI CLINextInstall and configure Terraform

Last updated 4 years ago

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:

  • , 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 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.

an image OCID
previous tutorial,