oracle-terraform-modules/terraform-oci-compute-instance

get latest image OCID dynamically

kral2 opened this issue ยท 0 comments

kral2 commented

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Sometimes we just want to launch an instance with the latest available image for a particular operating system, without having to check the exact OCID for each region on OCI Images documentation

Module user should be able to just indicate something like this: "use latest Oracle Linux 7.9 image matching my shape and region".

Additionally, we could potentially make the retrieved image OCID permanent so a recreate is not triggered when a newer version is available.

New or Affected Resource(s)

oci_core_instance for the source_id Input Variable.

Potential Terraform Configuration

We need to define a data source, similar to the one below:

data "oci_core_images" "images" {
    #Required
    compartment_id = var.compartment_id

    #Optional
    # display_name = var.image_display_name
    operating_system = "Oracle Linux"
    operating_system_version = "7.9"
    shape = var.shape
    sort_by = "TIMECREATED"
    sort_order = "DESC"
}

Then, we can target the image ocid with this expression:

data.oci_core_images.images.images[0].id

References

Data source: oci_core_images
OCI Images OCIDs reference