I am in the process of creating my own infrastructure in Oracle Cloud Infrastructure (OCI). I’ve set up a VCN (virtual cloud network) in Tokyo region and now I want to spin up a VM. I need to know which image to use and Terraform OCI provider requires image ID. Here is a way to list available images with their IDs (OCID) in OCI CLI.
oci compute image list -c $TENANCY_ID --region ap-tokyo-1 \
--query "data[*]".{'name:"display-name",id:id'} --output table
Here is the kind of data you’d get.
| ocid1.image.oc1.ap-tokyo-1.aaaaaaaaec34d6ybpedtu5sxhtwvurvdy4kp7bqr4ijnqiwvh75xxmkqnufq | Windows-Server-2019-Standard-Edition-VM-Gen2-2020.10.22-0 |
| ocid1.image.oc1.ap-tokyo-1.aaaaaaaatdmex2izbi7d7zdznvkyxdeygamojfnd3kroplg4d3p4i5rdnnra | Windows-Server-2019-Standard-Edition-VM-Gen2-2020.09.21-0 |
<SNIP>
| ocid1.image.oc1.ap-tokyo-1.aaaaaaaayqu2pdreelb4dtqyrroiyi5vzc4fkpgh24dnrhfdhbk2irkhetyq | Canonical-Ubuntu-20.04-Minimal-2020.08.24-0 |
| ocid1.image.oc1.ap-tokyo-1.aaaaaaaahk3krxqgimom7cy2z4b5lsoakm6bhmnbaaaincvgtuu4wivntxjq | Canonical-Ubuntu-20.04-2020.10.14-0 |
| ocid1.image.oc1.ap-tokyo-1.aaaaaaaa3ioe7z5wmi7lfk4xyoret7tmlyr2g2jowsqzh4hz6qcd5pakdtda | Canonical-Ubuntu-20.04-2020.09.07-0 |
| ocid1.image.oc1.ap-tokyo-1.aaaaaaaax6wjwsktl7kpl3zw3gfn34cqp76b36usraojs4jors3lmfmg52ba | Canonical-Ubuntu-20.04-2020.08.21-0 |
Take a note of the ID for the image you want to use and save it in one of the Terraform files to use it.
For a convenience, you may want to know how to list Shapes as well.
oci compute shape list -c $TENANCY_ID \
--query "data[*]".{'shape:shape,memory:"memory-in-gbs",ocpus:ocpus'} \
--output table
| 768.0 | 52.0 | BM.Standard2.52 |
| 2048.0 | 128.0 | BM.Standard.E3.128 |
<SNIP>
| 64.0 | 8.0 | VM.Standard.E2.8 |
| 1.0 | 1.0 | VM.Standard.E2.1.Micro |
| 56.0 | 8.0 | VM.Standard1.8 |