To start of managing Oracle Cloud Infrastructure (OCI) using Terraform Provider at first it’s needed to install Terraform and prepare provider configuration.

OCI Terraform provider supports three authentication methods:

  • API Key Authentication
  • Instance Principal Authorization
  • Security Token Authentication

Required keys and OCIDs can be generated by UI or commands from documentation. After getting or generating public key and private, they should be configured in .oci:

mkdir ~/.oci
more ~/.oci/config

[DEFAULT]
user=ocid1.user.oc1.***
fingerprint=***
tenancy=ocid1.tenancy.oc1.***
region=eu-frankfurt-1
key_file=~/.oci/oracleidentitycloudservice_my.cer 

To use all this settings in Terraform, enviroment variables can be set e.g. in .zshrc:

export TF_VAR_user_ocid=ocid1.user.oc1.***
export TF_VAR_fingerprint=***
export TF_VAR_tenancy_ocid=ocid1.tenancy.oc1.***
export TF_VAR_compartment_ocid=eu-frankfurt-1
export TF_VAR_private_key_path=~/.oci/oracleidentitycloudservice_my.cer

At the end we can provision infrastructure as a code:

terraform init
terraform plan
terraform apply