Install and configure Terraform

Install Terraform

Become root user, and let's perform a few updates

ubuntu@deploymentmachine:~$ sudo -i
root@deploymentmachine:~#
root@deploymentmachine:~#
root@deploymentmachine:~# apt-get update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Hit:2 http://eu-frankfurt-1-ad-3.clouds.archive.ubuntu.com/ubuntu focal InRelease
[...]

from link: https://learn.hashicorp.com/tutorials/terraform/install-cli

Hashicorp provides a very useful tuturial on how to install Terraform, depending on your OS:

Since my machine is on Ubuntu, I will perform the Linux steps:

  • Add key and official repository


root@deploymentmachine:~# curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
OK
root@deploymentmachine:~# apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
Get:1 https://apt.releases.hashicorp.com focal InRelease [4419 B]
Hit:2 http://eu-frankfurt-1-ad-3.clouds.archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://eu-frankfurt-1-ad-3.clouds.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://eu-frankfurt-1-ad-3.clouds.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:6 https://apt.releases.hashicorp.com focal/main amd64 Packages [17.9 kB]
Fetched 22.3 kB in 1s (40.6 kB/s)
Reading package lists... Done
  • Perform updates so changes can take place:

root@deploymentmachine:~# apt-get update
Hit:1 https://apt.releases.hashicorp.com focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:3 http://eu-frankfurt-1-ad-3.clouds.archive.ubuntu.com/ubuntu focal InRelease
Hit:4 http://eu-frankfurt-1-ad-3.clouds.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://eu-frankfurt-1-ad-3.clouds.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
  • Intall Terraform

root@deploymentmachine:~#
root@deploymentmachine:~# apt-get install terraform
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  terraform
0 upgraded, 1 newly installed, 0 to remove and 38 not upgraded.
Need to get 33.5 MB of archives.
After this operation, 81.8 MB of additional disk space will be used.
Get:1 https://apt.releases.hashicorp.com focal/main amd64 terraform amd64 0.14.5 [33.5 MB]
Fetched 33.5 MB in 6s (6042 kB/s)
Selecting previously unselected package terraform.
(Reading database ... 68575 files and directories currently installed.)
Preparing to unpack .../terraform_0.14.5_amd64.deb ...
Unpacking terraform (0.14.5) ...
Setting up terraform (0.14.5) ...
  • Check if installation has been a success by running a simple command:

root@deploymentmachine:~# terraform -version
Terraform v0.14.5
root@deploymentmachine:~#
root@deploymentmachine:~#

Setup Terraform for OCI Cloud

You will need to provide the following environment variables:

export TF_VAR_tenancy_ocid="ocid1.tenancy.oc1..aaaaaasomefaketenancyidinhereaaaaa323423421"
export TF_VAR_compartment_ocid="ocid1.tenancy.oc1..aaaaaasomefakecompartmentidinhereaaaaa323423422"
export TF_VAR_user_ocid="ocid1.user.oc1..aaaaaasomefakeuseridinhereaaaaa323423423"
export TF_VAR_fingerprint="2x:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
export TF_VAR_private_key_path="/root/.oci/oci_api_private_key.pem"

In case you have not setup your .oci folder or you are not aware how to find these details, check my tutorial on Install and configure OCI CLI - it explains step by step how to setup a fingerprint, a private key and how to find the rest of required information.

Once you have completed all these steps, go to next tutorial, Terraform - small test, to make sure your configuration is setup correctly.

Last updated