Launch Compute Instance

Summary

Before creating a compute instance, I need to know what subnets are available.

References

Launch Compute Instance

To find what compute shapes that are available, run the query in Find Available Compute Shapes, and select the appropriate one.

Run the following commands to launch a Centos 8 VM using an always free shape:

export sandbox_ocid=$(              \
    oci iam compartment list        \
        --name        'Sandbox'     \
        --query       'data[0].id'  \
        --raw-output                \
    )
export ad_name=$(                         \
    oci iam availability-domain list      \
        --compartment-id  ${sandbox_ocid} \
        --query           'data[0].name'  \
        --raw-output                      \
    )
export public_subnet_ocid=$(                        \
    oci network subnet list                         \
      --compartment-id  ${sandbox_ocid}             \
      --display-name    'public subnet-sandbox-vcn' \
      --query           'data[0].id'                \
      --raw-output                                  \
    )
export shape_name='VM.Standard.E2.1.Micro'
export centos_os='CentOS'
export centos_ver='8 Stream'
export centos_8_image_ocid=$(                           \
    oci compute image list                              \
        --compartment-id            ${sandbox_ocid}     \
        --lifecycle-state           AVAILABLE           \
        --operating-system          "${centos_os}"      \
        --operating-system-version  "${centos_ver}"     \
        --shape                     "${shape_name}"     \
        --query                     'data[0].id'        \
        --raw-output                                    \
    )
oci compute instance launch                                    \
    --availability-domain ${ad_name}                           \
    --compartment-id      ${sandbox_ocid}                      \
    --subnet-id           ${public_subnet_ocid}                \
    --assign-public-ip    true                                 \
    --display-name        'Sandbox public VM'                  \
    --hostname-label      'vm01'                               \
    --shape               ${shape_name}                        \
    --shape-config        '{"memoryInGBs": 1.0, "ocpus": 1.0}' \
    --image-id            ${centos_8_image_ocid}               \
    --wait-for-state      RUNNING                              \
    --wait-for-state      TERMINATED

Note: Even though the shape selected ('VM.Standard.E2.1.Micro') has a fixed shape, a --shape-config parameter is still required with the fixed shape configuration. See Compute Shapes for further details.

Sample output is upload as create-sandbox-vm01.log.

If the lifecycle state was TERMINATED, then use the procedure in Get Work Request Error to find the error message.