Series – Get your database running with Terraform part 1: Setup

One of my old colleague whom I had pleasure to work with many years ago asked recently if there would be guide on getting a database running on Oracle Cloud Infrastructure with Terraform using Infrastructure as Code.

That led me to an idea that I could write such guide and describe each step why it’s required and what are the key details on that service.

Different areas on this 10-part series will be:

  • OCI provider and Terraform setup
  • Compartments
  • VCN
  • Internet & NAT Gateway
  • Routetables
  • Subnets
  • Securitylists
  • Compute Instance
  • Database Instance
  • Wrapping it all up

Each post will have the required Terraform code and finally in the last post I will combine everything together so you can use it as a baseline. I’ll post the source code as well in the wrap-up.

Contrary to normal where I use Terraform modules this setup will not use modules but just a single folder having all necessary files in place to make the overall setup easier to understand.

After this series you will have a basic network with database running on private network and a compute instance to be used as a jump server in the public network which has access to the private network as well.

Setting up Terraform and OCI provider

This one is the easy part! Unless you are using Oracle Linux which automatically includes Terraform in the repository you will need to download Terraform from https://www.terraform.io/downloads.html .

Earlier you also had to download the OCI provider but now since OCI is an official provider it is included without further steps. Documentation and setup steps are described in the Terraform OCI provider page https://www.terraform.io/docs/providers/oci/index.html.

Creation of API key is described in detail here. On the same link you can see how to assign it for your user.

In short (and copied from above documentation) the values you need to setup as environment variables are:

  • tenancy_ocid – Can be found from the console under Administration->Tenancy Information
  • user_ocid – OCID for your user found under Indentity -> Users -> <My Username>
  • private_key_path – Location of created key on your machine
  • fingerprint – copy the fingerprint section from the added API key on your users info page
  • region – The region where you will be operating (I use eu-frankfurt-1)

On windows you can set these using setx command or by opening Environment variables under control panel and setting them.

Once these are set we can set the variables to be used in our Terraform file. I will have three files in this project – main.tf, variables.tf and outputs.tf.

In the main.tf I define environment variables in the provider section:

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}"} 

These variables come from variables.tf where they are referenced to come from the environment variables we have set.

variable "tenancy_ocid" {} // Your tenancys OCID
variable "user_ocid" {} // Your user's OCID
variable "fingerprint" {} // Fingerprint for the user key, can be found under user in console
variable "private_key_path" {} // Where your private key is located on the server you are running these scripts
variable "region" {} // Which region is used in OCI eg. eu-frankfurt-1 


Now all the necessary pre-requisistes have been done and we can start creating the resources in the next parts. Part 2 will discuss creation of compartments.

Simo

View Comments

Recent Posts

Helping to troubleshoot with OCI VCN Flow Logs

I'm a huge fan of using tools available to help troubleshoot any issues there are.…

3 days ago

OCI Routing checklist when using 3rd party firewall

This post will be checklist for items you'll need when you have Firewall (or Hub)…

1 year ago

OCI ExaCS Database Upgrade Rollback

Recently I was testing OCI database upgrade from 12c to 19c and ran into an…

1 year ago

Issues with OCI ExaCS PDB cloning

This is mostly just to document if you hit similar issues and how to get…

1 year ago

OCI Tips and Tricks – Managed MySQL Database in OCI (and trying out Heatwave)

Here I'm looking on how to provision MySQL DB on OCI, see how read replicas…

1 year ago

OCI Tips and Tricks: Create 19c Oracle Database (and manage it)

This time I go over on how to create 19c Oracle Database on OCI (hint:…

1 year ago