OCI - Manual creation of Instance from scratch

All the action provided here can be done from OCI console thru clicks. This is when you want to scripting thru OCI cli. You can either use cloudshell or install OCI module for your desktop.
Most of values we use is either configured in config or oci_cli_rc files.
As I use some of the resource very frequently, I had put, 
- user
- fingerprint
- key_file
- tenancy
- region
- compartment-id
- availability-domain

I had used CLI to configure from compartment to instance creation.

oci iam compartment create --name 'Ajit' --description "Testing OCI"

{

  "data": {

    "compartment-id": "ocid1.tenancy.oc1.....",

  ------------------------------------------------------------------------------------------------------------------------------

With that you have place to create your resources with assumption that proper quota is allocated.

Each compartment needs to have VCN for proper seperation.


oci network vcn create --cidr-block 192.168.0.0/16 --display-name AjitVcn1 --dns-label AjitDns1


This will allow us to carve out subnet in the vcn

oci network subnet create --cidr-block 192.168.10.0/24 --vcn-id ocid1.vcn.oc1.iad.... --security-list-ids '["ocid1.securitylist.oc1...."]'

Both vcn-id and security-list-ids is taken from "oci network vcn create" output


  ------------------------------------------------------------------------------------------------------------------------------

Now we can move to connect the vcn to connect to outside the instance vcn.

oci network internet-gateway create --is-enabled true --vcn-id ocid1.vcn.oc1.iad.... --display-name AjitGW

After opening up the Gateway for the vcn, we need to streamline who can connect to our GW.

Route table info can be seen in "oci network subnet create" output.

oci network route-table update --rt-id ocid1.routetable.oc1.iad.... --route-rules '[{"cidrBlock":"0.0.0.0/0","networkEntityId":"ocid1.internetgateway.oc1.iad...."}]'

  ------------------------------------------------------------------------------------------------------------------------------


All our setup to spin up compute is ready. Make sure you generate ssh key before you spin up the compute.

oci compute instance launch --display-name AjitVm --image-id ocid1.image.oc1.iad.... --subnet-id ocid1.subnet.oc1.iad.... --shape VM.Standard2.1 --assign-public-ip true --metadata '{"ssh_authored_keys":"ajit"}'


You can confirm the creation using "oci compute instance get"

Using the key, you can login thru opc user.