Skip to content

Instantly share code, notes, and snippets.

@scross01
Last active January 26, 2020 17:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scross01/bcd21c12b15787f3ae9d51d0d9b2df06 to your computer and use it in GitHub Desktop.
Save scross01/bcd21c12b15787f3ae9d51d0d9b2df06 to your computer and use it in GitHub Desktop.
Oracle Cloud Infrastructure (OCI) Terraform data sources to find base OS OCIDs https://docs.cloud.oracle.com/iaas/images/
data "oci_core_images" "autonomous_linux" {
compartment_id = "${var.tenancy_ocid}"
operating_system = "Oracle Autonomous Linux"
operating_system_version = "7.7"
# e.g. Oracle-Autonomous-Linux-7.7-2019.12-0"
filter {
name = "display_name"
values = ["^Oracle-Autonomous-Linux-([\\.0-9]+)-([\\.0-9-]+)$"]
regex = true
}
}
output "autonomous_linux" {
value = "${data.oci_core_images.autonomous_linux.images.0.id}"
}
# 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