Oracle Cloud Terraform: Infrastructure as Code for OCI and Oracle Database@Google Cloud

Terraform is an infrastructure-as-code tool that lets you provision and manage cloud infrastructure through declarative configuration. HashiCorp Terraform provides plugins called providers that let you interact with cloud providers and other APIs. The Terraform provider for Google Cloud can be used to provision and manage Google Cloud resources, including Oracle Database@Google Cloud. The OCI Terraform provider gives access to all of Oracle's cloud services, from compute instances and virtual networks to autonomous databases and container engines.

Terraform has a declarative and configuration-oriented syntax, which you can use to describe the infrastructure that you want to provision in your Google Cloud project. After you author this configuration in one or more Terraform configuration files, you can use the Terraform CLI to apply this configuration to your Oracle Database@Google Cloud resources.

The following steps explain how Terraform works:

  • You describe the infrastructure you want to provision in a Terraform configuration file. You don't need to write code describing how to provision the infrastructure. Terraform provisions the infrastructure for you.
  • You run the terraform plan command, which evaluates your configuration and generates an execution plan.
  • Each resource block describes one or more infrastructure objects, such as virtual networks or compute instances.

Terraform is an Infrastructure as Code tool developed by Hashicorp that allows you to define, provision, and manage your infrastructure across multiple cloud providers using the Terraform language syntax, HCL. Terraform enables you to automate the entire lifecycle of your cloud infrastructure, making it easy to build, update, and scale resources in a consistent and reproducible manner. Terraform is widely used by DevOps teams to manage cloud resources, improve infrastructure efficiency, reduce manual errors and version control cloud resources.

Terraform Fundamentals and Provider Architecture

Terraform providers are the interface between Terraform core and cloud APIs. The Oracle Cloud Infrastructure provider requires more configuration than some other cloud providers because of its authentication model, but once you understand the structure it becomes straightforward.

Infrastructure as code lets you safely build, change, and manage infrastructure. The core workflow revolves around authoring, planning, and applying configuration.

The basic Terraform workflow steps are:

  • Author configuration
  • Run terraform plan to evaluate configuration and generate an execution plan
  • Run terraform apply to create resources
  • Run terraform destroy to remove resources

A typical provider configuration for OCI requires several pieces of information for authentication.

Working with Oracle Database@Google Cloud via Terraform

This page introduces you to using Terraform with Oracle Database@Google Cloud, including an introduction to how Terraform works and some resources to help you get started using Terraform with Google Cloud. You'll also find links to Terraform reference docs for Oracle Database@Google Cloud, code examples, and guides for using Terraform to provision Oracle Database@Google Cloud resources.

The Terraform resources available for Oracle Database@Google Cloud include:

Terraform configuration sample Terraform resource Data sources
Exadata Infrastructure googleoracledatabasecloudexadata_infrastructure
Exadata VM Cluster googleoracledatabasecloudvm_cluster
Autonomous AI Database googleoracledatabaseautonomousdatabase

What's next resources for this integration include Terraform code samples for Oracle Database@Google Cloud, Terraform on Google Cloud documentation, Google Cloud provider documentation in HashiCorp, and Infrastructure as code for Google Cloud.

Getting Started with Terraform on Oracle Cloud Infrastructure

Get Started with Terraform in Oracle Cloud Infrastructure

This tutorial helps you to start your journey into leveraging IaC for deploying and managing your cloud infrastructure.

The tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.

It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.

Objectives for a beginner OCI Terraform journey are:

  • Install, configure and use Terraform in Oracle Cloud Infrastructure for MacOS and Windows
  • Build, change, and destroy a virtual cloud network and subnet on Oracle Cloud Infrastructure using Terraform
  • Authenticate to Oracle Cloud Infrastructure, and create a Virtual Cloud Network
  • Write, format and validate a Terraform configuration
  • Plan and apply the configuration to create a VCN OCI resource
  • Add a subnet to your Oracle Cloud Infrastructure VCN
  • Modify the subnet display name and plan changes to update the resource in place
  • Learn how Terraform handles infrastructure change management
  • Destroy the Oracle Cloud Infrastructure VCN and subnet created in previous tutorials
  • Evaluate the plan and confirm the destruction
  • Declare your OCI region and compartment ID as variables
  • Reference the variable in Terraform configuration

The tutorial shows how to set up Terraform to manage Oracle Cloud Infrastructure, configure the OCI CLI on macOS and Windows, and create an OCI compartment with Terraform. It includes sample commands, Terraform code snippets, configuration tips, and suggested places where you would add graphical snapshots in your documentation or blog.

Installation and Environment Prerequisites

Install Terraform on Mac, Linux, or Windows by downloading the binary or using a package manager. Homebrew or Chocolatey are referenced as package manager options.

Prerequisites for working with the OCI Terraform provider:

  • Terraform 1.0 or later
  • An Oracle Cloud Infrastructure account
  • An OCI API signing key pair
  • Your tenancy OCID, user OCID, and compartment OCID

Before you begin a set up tutorial, you must have:

  • An Oracle Cloud Infrastructure account. See Request and Manage Free Oracle Cloud Promotions.
  • A MacOS, Linux, or Windows environment:
    • MacOS
    • Linux (Any distribution)
  • You can install a Linux VM with an Always Free Compute shape, on Oracle Cloud Infrastructure.
  • Oracle Cloud Infrastructure Cloud Shell

The tutorial uses an Oracle Linux VM environment with an AMD shape for its examples, but you can use any environment mentioned in this section.

Prepare your environment for authenticating and running Terraform scripts. Also, gather the information your account needs to authenticate the scripts.

Skip creating RSA keys if you're using Cloud Shell or Resource Manager.

Authentication Model and Provider Setup

Set up Oracle Cloud Infrastructure Terraform provider scripts, documented in the Terraform Registry, to connect to an OCI account. Confirm the setup by fetching information from the tenancy.

Key tasks include how to:

  • Create RSA keys.
  • Set up Oracle Cloud Infrastructure Terraform provider scripts
  • Authenticate your Terraform scripts
  • Get information about the availability domains in your tenancy

OCI authentication requires several pieces of information. Gathering required information is a prerequisite step.

Setting up the OCI provider involves a bit more configuration than some other cloud providers because of its authentication model, but once you understand the structure it becomes straightforward. This guide covers everything from initial authentication to managing the most common OCI resources.

A minimal provider block pattern is:

hcl provider "oci" { tenancy_ocid = var.tenancy_ocid user_ocid = var.user_ocid fingerprint = var.fingerprint private_key_path = var.private_key_path region = var.region }

Authentication to Oracle Cloud Infrastructure is required before creating resources.

Core Workflow: Build, Change, Destroy

Build infrastructure

Authenticate to Oracle Cloud Infrastructure, and create a Virtual Cloud Network. Write, format and validate a Terraform configuration. Plan and apply the configuration to create an VCN OCI resource.

Change infrastructure

Add a subnet to your Oracle Cloud Infrastructure VCN. Modify the subnet display name and plan changes to update the resource in place. Learn how Terraform handles infrastructure change management.

Destroy infrastructure

Destroy the Oracle Cloud Infrastructure VCN and subnet you created in the previous tutorials. Evaluate the plan and confirm the destruction.

The workflow is presented as step-by-step command-line tutorials that walk through Terraform basics for the first time.

Video and tutorial durations referenced in learning materials include:

  • Install Terraform 7min
  • Install Terraform 13min
  • Build infrastructure 6min
  • Change infrastructure 5min
  • Destroy infrastructure 6min

Input Variables and Configuration Patterns

Define input variables

Declare your OCI region and compartment ID as variables. Reference the variable in Terraform configuration.

Terraform Architecture Workflow is a core concept for organizing modules and state.

Sample variable declarations:

```hcl
variable "region" {
description = "OCI region"
type = string
}

variable "compartment_id" {
description = "Compartment OCID"
type = string
}
```

Using variables keeps configuration portable across environments and teams.

Best Practices and Operational Considerations

Oracle Cloud Infrastructure has grown into a serious contender in the cloud market, especially with its Always Free tier and competitive pricing on compute and database services.

Terraform is a powerful Infrastructure as Code tool that allows you to define and provision cloud resources in a declarative way.

For Oracle Database@Google Cloud, Terraform provides a declarative path to provision Exadata Infrastructure, Exadata VM Cluster, and Autonomous AI Database resources through Google Cloud provider resources.

For OCI, common resources managed via Terraform include compartments, virtual cloud networks, subnets, compute instances, autonomous databases, and container engines.

Authentication best practices include using API signing key pairs, storing tenancy OCID, user OCID, and compartment OCID as variables, and never hardcoding secrets.

Conclusion

Terraform provides a consistent infrastructure as code experience for both Oracle Cloud Infrastructure and Oracle Database@Google Cloud. The declarative HCL syntax, plan-apply-destroy cycle, and provider model allow teams to automate the entire lifecycle of cloud infrastructure with reproducible builds.

For OCI, success depends on proper authentication setup with RSA keys, tenancy OCID, user OCID, compartment OCID, and region configuration. The build-change-destroy workflow demonstrated through VCN and subnet examples shows how Terraform handles safe updates and teardown.

For Oracle Database@Google Cloud, Terraform resources such as googleoracledatabasecloudexadatainfrastructure, googleoracledatabasecloudvmcluster, and googleoracledatabaseautonomousdatabase enable provisioning of database infrastructure through Google Cloud provider configuration.

The combination of Always Free tier options, competitive pricing, and Terraform automation makes OCI an efficient platform for DevOps teams to manage cloud resources, improve infrastructure efficiency, reduce manual errors and version control cloud resources.

Sources

  1. docs.cloud.google.com/oracle/database/docs/terraform
  2. docs.oracle.com/en/learn/oci-terraform-for-beginners/index.html
  3. developer.hashicorp.com/terraform/tutorials/oci-get-started
  4. www.linkedin.com/pulse/terraform-manage-oracle-cloud-infrastructure-oci-part-1-cosmicro-6wcvc
  5. oneuptime.com/blog/post/2026-02-23-how-to-configure-oci-oracle-cloud-provider-in-terraform/view
  6. docs.oracle.com/en-us/iaas/Content/dev/terraform/tutorials/tf-provider.htm

Related Posts