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

Terraform Module for creating Oracle Cloud Infrastructure compute instances
https://registry.terraform.io/modules/oracle-terraform-modules/compute-instance/oci/latest
Other
46 stars 62 forks source link

get latest image OCID dynamically #78

Open kral2 opened 2 years ago

kral2 commented 2 years ago

Community Note

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