8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Misc » Here

Terraform : Oracle Cloud Infrastructure (OCI) General Information

This article describes how to display some commonly used information from Oracle Cloud Infrastructure (OCI), needed when using Terraform. This script is displaying information, not creating any new resources.

Related articles.

Create Working Directory

Create a new working directory and switch to that directory.

mkdir \git\oraclebase\terraform\oci\oci_general_info
cd \git\oraclebase\terraform\oci\oci_general_info

In a previous article (here) we discussed the creation of an OCI provider. Copy the OCI provider information into this new working directory.

copy \git\oraclebase\terraform\oci\oci_provider\*.tf .
copy \git\oraclebase\terraform\oci\oci_provider\*.tfvars .

oci_general_info.tf

Create a file called "oci_compute.tf" with the following contents.

# Variables
variable "compartment_id" { type = string }

variable "operating_system" { 
  type    = string
  default = "Oracle Linux"
}

variable "operating_system_version" { 
  type    = string
  default = "8"
}

variable "shape" { 
  type    = string
  default = "VM.Standard.E2.1.Micro"
}


# Resources
data "oci_identity_availability_domains" "ads" {
  compartment_id = var.compartment_id
}

data "oci_core_images" "tf_images" {
  compartment_id           = var.compartment_id
  operating_system         = var.operating_system
  operating_system_version = var.operating_system_version
  shape                    = var.shape
}

data "oci_core_shapes" "tf_shapes" {
  compartment_id      = var.compartment_id
  image_id            = data.oci_core_images.tf_images.images.0.id
}


# Outputs
output "first_availability_domain_name" {
  value = data.oci_identity_availability_domains.ads.availability_domains[0].name
}

output "availability_domain_names" {
  value = data.oci_identity_availability_domains.ads.availability_domains[*].name
}

output "latest_image_id" {
  value = data.oci_core_images.tf_images.images[0].id
}

output "shape_names" {
  value = data.oci_core_shapes.tf_shapes.shapes[*].name
}

The file begins with variable definitions. We could set default values for these variables, or use literal values directly in the provider definition, but we don't want sensitive information checked into version control, so it makes sense to separate out variable values from the script. Many of the parameters are defaulted. The resources section defines availability domains, images and shapes using the input variables. The outputs section allows us to see information about the availability domains, images and shapes.

The variables, resources and outputs sections can be split into separate files if you find that organisation easier. It may help for more complex definitions.

The full list of parameters and outputs available can be found here.

oci_general_info_variables.auto.tfvars

There are a number of ways to supply values for input variables (see here). In this example we'll use a ".auto.tfvars" file. We won't check this script into version control as it contains sensitive information.

Create a file called "oci_general_info_variables.auto.tfvars".

# Amend with your details.
compartment_id = "ocid1.compartment.oc1..aaaaaaaa..."
operating_system         = "Oracle Linux"
operating_system_version = "8"
shape                    = "VM.Standard.E2.1.Micro"

The compartment_id is the OCID of the compartment that will house the resources you are planning to build. You must adjust it with a valid value from your Oracle Cloud account. You would not normally use the root compartment for this. You can get the ID of a compartment from your Oracle Cloud account as follows.

Display the OCI General Information

Initialize the working directory using the terraform init command.

terraform init

Use the terraform plan command to display the general information.

terraform plan

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + availability_domain_names      = [
      + "oVQK:UK-LONDON-1-AD-1",
      + "oVQK:UK-LONDON-1-AD-2",
      + "oVQK:UK-LONDON-1-AD-3",
    ]
  + first_availability_domain_name = "oVQK:UK-LONDON-1-AD-1"
  + latest_image_id                = "ocid1.image.oc1.uk-london-1.aaaaaaaa..."
  + shape_names                    = [
      + "BM.Standard2.52",
      + "BM.Standard.E3.128",
      + "BM.Standard.E2.64",
      + "BM.Standard1.36",
      + "VM.Standard.E3.Flex",
      + "VM.Standard2.1",
      + "VM.Standard2.2",
      + "VM.Standard2.4",
      + "VM.Standard2.8",
      + "VM.Standard2.16",
      + "VM.Standard2.24",
      + "VM.Standard.E2.1",
      + "VM.Standard.E2.2",
      + "VM.Standard.E2.4",
      + "VM.Standard.E2.8",
      + "VM.Standard.E2.1.Micro",
      + "VM.Standard1.1",
      + "VM.Standard1.2",
      + "VM.Standard1.4",
      + "VM.Standard1.8",
      + "VM.Standard1.16",
      + "BM.Standard2.52",
      + "BM.Standard.E3.128",
      + "BM.Standard.E2.64",
      + "BM.Standard1.36",
      + "VM.Standard.E3.Flex",
      + "VM.Standard2.1",
      + "VM.Standard2.2",
      + "VM.Standard2.4",
      + "VM.Standard2.8",
      + "VM.Standard2.16",
      + "VM.Standard2.24",
      + "VM.Standard.E2.1",
      + "VM.Standard.E2.2",
      + "VM.Standard.E2.4",
      + "VM.Standard.E2.8",
      + "VM.Standard1.1",
      + "VM.Standard1.2",
      + "VM.Standard1.4",
      + "VM.Standard1.8",
      + "VM.Standard1.16",
      + "BM.Standard2.52",
      + "BM.Standard.E3.128",
      + "BM.Standard.E2.64",
      + "BM.Standard1.36",
      + "VM.Standard.E3.Flex",
      + "VM.Standard2.1",
      + "VM.Standard2.2",
      + "VM.Standard2.4",
      + "VM.Standard2.8",
      + "VM.Standard2.16",
      + "VM.Standard2.24",
      + "VM.Standard.E2.1",
      + "VM.Standard.E2.2",
      + "VM.Standard.E2.4",
      + "VM.Standard.E2.8",
      + "VM.Standard1.1",
      + "VM.Standard1.2",
      + "VM.Standard1.4",
      + "VM.Standard1.8",
      + "VM.Standard1.16",
    ]

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

The output shows the availability domains for the compartment, latest image for the specified operating system in the compartment, and the shapes available for the operating system in the compartment.

For more information see:

Hope this helps. Regards Tim...

Back to the Top.