Friday, June 12, 2020

Install Terraform for OCI in linux.

6:31 AM Posted by Dilli Raj Maharjan , No comments

Terraform is the infrastructure as code offering from HashiCorp. It is a tool for building, changing, and managing infrastructure in a safe, repeatable way. Operators and Infrastructure teams can use Terraform to manage environments with a configuration language called the HashiCorp Configuration Language (HCL) for human-readable, automated deployments.

Advantages of using terraform:

1. Platform Agnostic
        It can manage a heterogeneous environment (AWS, GCP, OCI, etc) with the same workflow by creating a configuration file.
2. State Management
        Terraform uses this local state to create plans and make changes to your infrastructure
        Terraform state is the source of truth by which configuration changes are measured.
        If any changes are made to the configuration file, terraform compares those with the state file to determine what changes result in a new resource.
3. Operator Confidence
       When we execute terraform apply, we will be prompted to review the proposed changes and must affirm the changes, or else Terraform will not apply the proposed plan.

Installation is quite easy. Following is a step by step installation guide for terraform with OCI.

Root privilege is not required for installation. I have used user terraform to install and configure terraform and OCI CLI.

Install OCI CLI.

Switch to the desired user and executed following command to download and execute
bash -c "$(curl -L"

You will be prompted for an install location. Just press enter if default location works.

Installation in progress #####.

Installation in progress ##########.

Finally, Installation completed. Installation will add the location of the oci binary to PATH env variables.

Verify the oci is available.

Check oci version with --version option

Configure oci with command below
oci setup config

You will be prompted for config location, user ocid, tenancy ocid, region and for API signing key. Create API singing key.

Once the oci cli setup is completed login to the OCI console and click on the user under the Profile section.

On the left-hand side under Resources section Click on API Keys.

In API Keys page click on Add Public Key

Select to PASTE PUBLIC KEYS and Paste public key created during the oci cli setup. The default name of the Public key will be oci_api_key_public.pem. Once you pasted public key Click on Add to continue.

Install terraform.

Open site

Select Operation System as per your host and the architecture. In my case, I am going to install a terraform on Linux 64 bit. Click on the link and download the terraform or copy link and use wget to download the terraform.

Downloading terraform using wget command.

Once download is complete unzip compressed terraform.

Move terraform binary to executable directory and type terraform --version to display version information. Terraform installed successfully and ready to execute terraform configuration.


Post a Comment