Terraform: Getting the Latest OS Image

When provisioning a compute instance, you may want to grab the latest available version, as Oracle frequently updates its images. The list below shows the current Oracle Linux images:

As you can see, there are multiple images for Oracle Linux 6.10 and 7.5. To get the latest 7.5 for example, you have to look at the time-crated or the display name, and pick the latest one.

Fortunately, the OCI terraform data provider for images automatically sorts the image list by date descending. So you can simply filter by operating system and version, and pick the first element (index 0) from the list. This will be the latest image version.

The syntax to fetch the latest image requires a filter with a regular expression in order to filter out the GPU images that are only available for certain bare metal shapes:

 

The values attribute of the filter contains a regular expression to filter out the display names that begin with “Oracle-Linux-” followed by a version number and creation date. This filters out the images with GPU in the name. Specifying the shape is optional but highly recommended so that you only get images that fit your shape.

Enjoy!

 

 

 

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *