This README describes the steps to setup your environment so it can run Terraform modules on OCI.
First we need to install Terraform. Instructions on that are here. You can test that the install was successful by running the command:
terraform You should see something like:
Next you're going to need to install the Terraform Provider for Oracle Cloud Infrastructure. I'm on a Mac, so I downloaded a copy of the binary, darwin_amd64.tar.gz from here and put it in a new plugins directory. To do that, I ran the following commands:
cd ~/.terraform.d mkdir plugins cd plugins curl -L https://github.com/oracle/terraform-provider-oci/releases/download/v2.2.1/darwin_amd64.tar.gz > darwin_amd64.tar.gz tar -xvf darwin_amd64.tar.gz rm darwin_amd64.tar.gz ls That gave this output:
Create an SSH keypair for connecting to VM instances by follow these instructions. You really just need to do this:
ssh-keygen -t rsa -N "" -b 2048 -f ~/.ssh/oci Now, create a key for OCI API access by following the instructions here. Basically, you need to run these commands:
mkdir ~/.oci openssl genrsa -out ~/.oci/oci_api_key.pem 2048 openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem cat ~/.oci/oci_api_key_public.pem | pbcopy When complete, open a web browser to the console here. Then select your user, click "Add Public Key" and paste it into the dialog.
Now, let's take a look at the env-vars file.
The script pulls values from the keys you created in the earlier steps. You'll need to update three fields with values you can find in the console:
- TF_VAR_tenancy_ocid
- TF_VAR_user_ocid
- TF_VAR_compartment_ocid
When you've set all the variables, source the file with the command:
source env-vars With that, you're all ready to start running Terraform commands!



