Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Oracle Cloud Infrastructure (OCI) Terraform data sources to find base OS OCIDs https://docs.cloud.oracle.com/iaas/images/
# use the full display name to lock to a specific verison
data "oci_core_images" "oraclelinux-7_5-2018_09_25" {
compartment_id = "${var.compartment_ocid}"
display_name = "Oracle-Linux-7.5-2018.09.25-0"
}
output "oraclelinux-7_5-2018_09_25" {
value = "${data.oci_core_images.oraclelinux-7_5-2018_09_25.images.0.id}"
}
# gets the Oracle Linux 7.5 images, the first result in the images list (index 0) is the latest patched version
# filter to specific display name pattern to include only GPU images
data "oci_core_images" "oraclelinux-7_5-gpu" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Oracle Linux"
operating_system_version = "7.5"
# include only GPU specific images
filter {
name = "display_name"
values = ["^.*-GPU-.*$"]
regex = true
}
}
output "ol-7_5-gpu-latest_ocid" {
value = "${data.oci_core_images.oraclelinux-7_5-gpu.images.0.id}"
}
# gets the Oracle Linux 7.5 images, the first result in the images list (index 0) is the latest patched version
# filter to specific display name pattern to exclude the GPU images
data "oci_core_images" "oraclelinux-7_5" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Oracle Linux"
operating_system_version = "7.5"
# exclude GPU specific images
filter {
name = "display_name"
values = ["^([a-zA-z]+)-([a-zA-z]+)-([\\.0-9]+)-([\\.0-9-]+)$"]
regex = true
}
}
output "ol-7_5-latest_ocid" {
value = "${data.oci_core_images.oraclelinux-7_5.images.0.id}"
}
# gets the Ubuntu 16.04 images, the first result in the images list (index 0) is the latest patched version
# filter to specific display name pattern to include the GPU images
data "oci_core_images" "ubuntu-16_04-gpu" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Canonical Ubuntu"
operating_system_version = "16.04"
# include only GPU specific images
filter {
name = "display_name"
values = ["^.*-GPU-.*$"]
regex = true
}
}
output "ubuntu-16_04-gpu-latest" {
value = "${data.oci_core_images.ubuntu-16_04-gpu.images.0.id}"
}
# gets the Ubuntu 16.04 images, the first result in the images list (index 0) is the latest patched version
# filter to specific display name pattern to exclude the GPU images
data "oci_core_images" "ubuntu-16_04" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Canonical Ubuntu"
operating_system_version = "16.04"
# exclude GPU specific images
filter {
name = "display_name"
values = ["^([a-zA-z]+)-([a-zA-z]+)-([\\.0-9]+)-([\\.0-9-]+)$"]
regex = true
}
}
output "ubuntu-16_04-latest_ocid" {
value = "${data.oci_core_images.ubuntu-16_04.images.0.id}"
}
# gets the Windows 2016 Datacenter Bare Metal *AMD* images
# the first result in the images list (index 0) is the latest patched version
data "oci_core_images" "windows-server-2016-datacenter-BM-amd" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Windows"
operating_system_version = "Server 2016 Datacenter"
# Bare Metal AMD (`BM-Gen2-E2`) varient only
filter {
name = "display_name"
values = ["^Windows-Server-2016-Datacenter-Edition-BM-Gen2-E2-([\\.0-9-]+)$"]
regex = true
}
}
output "windows-server-2016-datacenter-BM-amd-latest" {
value = "${data.oci_core_images.windows-server-2016-datacenter-BM-amd.images.0.id}"
}
# gets the Windows 2016 Datacenter Bare Metal *Intel* images
# the first result in the images list (index 0) is the latest patched version
data "oci_core_images" "windows-server-2016-datacenter-BM-intel" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Windows"
operating_system_version = "Server 2016 Datacenter"
# Bare Metal Intel (`BM-Gen2`) varient only
filter {
name = "display_name"
values = ["^Windows-Server-2016-Datacenter-Edition-BM-Gen2-([\\.0-9-]+)$"]
regex = true
}
}
output "windows-server-2016-datacenter-BM-intel-latest" {
value = "${data.oci_core_images.windows-server-2016-datacenter-BM-intel.images.0.id}"
}
# gets all Windows 2016 Standard VM images
# the first result in the images list (index 0) is the latest patched version
data "oci_core_images" "windows-server-2016-standard-VM" {
compartment_id = "${var.compartment_ocid}"
operating_system = "Windows"
operating_system_version = "Server 2016 Standard"
filter {
name = "display_name"
values = ["^Windows-Server-2016-Standard-Edition-VM-Gen2-([\\.0-9-]+)$"]
regex = true
}
}
output "windows-server-2016-standard-VM-latest" {
value = "${data.oci_core_images.windows-server-2016-standard-VM.images.0.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.