Simplify the automation of Oracle Linux deployments with Terraform on OCI

February 22, 2023 | 5 minute read
Gursewak Sokhi
Technical Product Manager - Oracle Linux & Virtualization
Text Size 100%:

As businesses increase their use of DevOps and cloud native technologies to drive productivity and performance, it’s easy to assume their IT infrastructure is managed seamlessly. But many developers are still manually managing thousands of processes across their enterprise environments. Terraform, an open source infrastructure-as-code tool created by Hashicorp, helps solve this problem by allowing DevOps teams to build, provision, and change resources on cloud platforms. Both developers and operations teams can easily apply Terraform to define resources through human-readable configuration files and deploy them in minutes.

In Oracle Cloud Infrastructure (OCI), you can lay out your entire infrastructure and maximize efficiency using Terraform. As an OCI customer, you can automate the creation of Compute instances or database systems using Terraform instead of manually using the Oracle Cloud Console. While performing these tasks through the Console might not appear overly complicated when dealing with just one or two systems, as you scale up to managing over 100 systems, relying solely on the console to create Compute instances can significantly impede the pace of your workflow.

By automating these tasks through Terraform, you can streamline the process and increase efficiency. Terraform becomes a helping hand in automating the process. This blog presents a high-level Terraform workflow to deploy an Oracle Linux instance in OCI, where we showcase how simple Terraform and its declarative language are when it comes to automation.

Why Oracle Linux in OCI? Oracle Linux is a proven operating system featuring the Unbreakable Enterprise Kernel (UEK), Oracle’s optimized Linux kernel built to provide security features and deliver superior performance. Not only does it power the systems of many enterprise customers, but it’s also the backbone of Oracle Cloud Infrastructure itself. Customers with OCI subscriptions benefit from Oracle Linux Premier Support, the highest-level support, at no extra cost. Premier Support allows you to take advantage of many benefits, such as Oracle Ksplice zero-downtime updates, Oracle Linux Automation Manager, and Oracle Cloud Native Environment.

Deploying an Oracle Linux instance using Terraform

When it comes to writing the Terraform files, you can use your editor of choice, such as Visual Studio Code. You can then upload the files to OCI Cloud Shell, a small virtual machine (VM) running a Bash shell, to run Terraform without having to install it. A Terraform workflow is composed of three simple stages: Write, plan, and apply. For simplicity purposes, we have modified and are showing only a portion of the Terraform template code obtained from our GitHub examples.


After collecting information for the infrastructure resources to be built, input variables are declared, such as general OCI and Compute instance parameters, typically in a file called These variables act as function arguments with values that you can assign. By defining these variables, Terraform modules written in can be modified without having to change their own source code.

For example, source_type and source_ocid are the variables that identify the type of source (An operating system image) and then the specific source (An Oracle Linux image in our case) to use for the instance. When creating an instance with an Oracle Linux 9 image, you can navigate to the release notes to retrieve the image OCID of an Oracle Linux 9 image for the region in which the instance will be created. That image is the string value you assign to the source_ocid variable. You can provide a value, such as 50, to a variable like instance_count and deploy identical instances from a single module instead of doing it manually through the Console. Automation provides this value.

A screenshot of the code for and in Terraform.

The image OCID is assigned to the source_ocid variable in the terraform.tfvars as shown in the following graphic with the image OCID of “Oracle-Linux-9.1-2023.01.31-2” correlating to the us-ashburn-1 region. Using this file, values for the declared variables in can be assigned or the default ones can be overwritten.

A screenshot of the terraform.tfvars code details in Terraform.


After the Terraform configuration files have been written with values specific to your cloud environment, upload them to OCI Cloud Shell. In the directory where your Terraform configuration files are located, run the terraform init command to initialize the directory. Then, run the terraform plan command to create an execution plan, which includes a preview of changes for deploying the instance.

gursewak_s@cloudshell:tfDemo (us-ashburn-1)$ terraform init


gursewak_s@cloudshell:tfDemo (us-ashburn-1)$ terraform plan


The generated Terraform plan is executed by running the terraform apply command. This command creates the instance with an Oracle Linux 9 image on OCI for our example.

gursewak_s@cloudshell:tfDemo (us-ashburn-1)$ terraform apply

Start automating your cloud deployments today

Terraform helps accelerate DevOps, reduce manual intervention, and, crucially, automate your cloud infrastructure. Oracle and the OCI community develop, maintain, and publish Terraform projects for many OCI resources on GitHub. These projects and their Terraform configuration files can be used as templates and make a great starting point.

If you want to access detailed examples that show how to use the modules for deploying a Compute instance, see the details on GitHub. You can also learn to deploy an Oracle Linux instance on OCI using Terraform through the lab exercise from Oracle Help Learn Center.

If you don’t have an OCI subscription, sign up for Oracle Cloud Free Tier, which includes Always Free cloud services for an unlimited time and a 30-day trial with $300 of cloud credits. This way, you can gain hands-on experience with Terraform and launch an Oracle Linux deployment on Oracle Cloud Infrastructure.

For more information, see the following resources:

Gursewak Sokhi

Technical Product Manager - Oracle Linux & Virtualization

Gursewak Sokhi is a Technical Product Manager for Oracle Linux and Virtualization. He holds a Computer Engineering B.S. with a concentration in Systems Programming, and a Mathematics and Economics B.A. from the University of California, Santa Cruz.

Connect with him on LinkedIn:

Previous Post

Using the Maple Tree to expand NR_IRQs on ARM

Greg Marsden | 1 min read

Next Post

irqbalance: design and internals

Imran Khan | 13 min read