In our TerraForm SME series
Today we will check on how to set up connectivity with TerraForm and OCI. One thing to note, to complete TerraForm certification no need to have much knowledge about cloud providers. The main focus will be the concepts of TerraForm. The same concepts will apply to all Cloud providers. It is the one best feature. TerraForm learn once, manage multi-vendor cloud platform
How to set up TerraForm Lab Oracle Cloud or OCI?
TerrafForm -> Authentication method -> Connect to cloud.
Same for all Cloud providers. The authentication part varies from cloud to cloud. Now let’s see the sample authentication part for OCI. OCI supports 3 types of authentication types for TerraForm. Let’s see API key-based Authentication method.
OCI TerraForm sample authentication file to connect TerraForm to OCI.
[tf@localhost .oci]$ ls
lab.pem lab_public.pem list.tf provider.tf terraform.tfstate terraform.tfstate.backup
[tf@localhost .oci]$ cat provider.tf
provider "oci" {
tenancy_ocid = "ocid1.tenancy.oc1..yourocid"
user_ocid = "ocid1.user.oc1..yourocid"
private_key_path = "/home/tf/.oci/lab.pem"
fingerprint = "bb:79:your OCI fingerprint vaule "
region = "us-ashburn-1"
}
Provider authentication details you can mention in the same .tf file as you going to use or r separate file like above.
Now let’s check our connectivity with OCI using TerraForm with the following sample .tf. It lists the current image id available on OCI for OS Oracle 7.
Leets place the following code in list.tf
[tf@localhost .oci]$ cat list.tf
# get latest CentOS 7 image
data "oci_core_images" "centos-7" {
compartment_id = "ocid1.compartment.oc1..your oCID"
operating_system = "CentOS"
operating_system_version = "7"
sort_by = "TIMECREATED"
sort_order = "DESC"
}
output "centos-7-latest-name" {
value = data.oci_core_images.centos-7.images.0.display_name
}
output "centos-7-latest-id" {
value = data.oci_core_images.centos-7.images.0.id
}
Now run commands
1. terraform init
2. terraform plan
3. terraform apply
These are common for all cloud providers. We will learn about it in the next lesson. Our goal is to check Lab connections.


Now we are able to connect TerraForm with OCI. Now all set. Next, we will start our TerraForm SME certification lesson number one.