Getting Started with Terraform and OCI (Oracle Cloud) Part 1: Creating Network Resources

Guillermo Musumeci
8 min readJan 4

--

Terraform is the most popular Infrastructure as Code (IaC) tool in the market, and in this Getting Starting with Terraform and OCI series, we will learn how to write Terraform code to automate our cloud infrastructure in Oracle Cloud.

  • Part 1: Deploying network resources in OCI — this story
  • Part 2: Implementing Security List and Network Security Group (NSG) — coming soon

In this story, we will take a look at the following subjects:

  • Define the OCI Provider for Terraform
  • Create a Compartment
  • Create a Virtual Cloud Network (VCN)
  • Create Private and Public Subnets
  • Deploy an Internet Gateway
  • Deploy a NAT Gateway
  • Create Route Tables
  • Create DHCP Options

1. Requirements

2. Defining the OCI Provider

Now it is time to create the Terraform code to connect with the OCI Provider and the first step is to create the “provider-variables.tf” file:

variable "oci_tenancy" {
type = string
description = "OCI tenancy identifier"
}

variable "oci_user" {
type = string
description = "OCI user identifier"
}

variable "oci_fingerprint" {
type = string
description = "OCI fingerprint for the key pair"
}

variable "oci_key" {
type = string
description = "OCI key pair"
}

variable "oci_region" {
type = string
description = "OCI region"
}

variable "oci_root_compartment" {
type = string
description = "OCI root compartment"
}

then we create the “provider-main.tf” to initialize Terraform and OCI providers.

Note: I prefer to define the provider in separate files, for more clarity, however some people prefer to add to the main.tf or versions.tf files.

--

--

Guillermo Musumeci

Certified AWS, Azure & GCP Architect | HashiCorp Ambassador | Terraform SME | KopiCloud Founder | ex-AWS | Entrepreneur | Book Author | Husband & Dad of ✌