How to install Terraform on Linux (Ubuntu) and Link AWS User Credentials to it.

tbello

Oluwatomisin Bello

Posted on February 5, 2023

How to install Terraform on Linux (Ubuntu) and Link AWS User Credentials to it.

In this tutorial you would be needing an AWS console account and a Linux machine.

1.) Run the command below in a bash terminal to update the Linux software repository.

sudo apt update
Enter fullscreen mode Exit fullscreen mode

2.) The next step after updating the Linux software repository is to install the following packages:

  • gnupg
  • software-properties-common
sudo apt-get install -y gnupg software-properties-common

Enter fullscreen mode Exit fullscreen mode

3.) Download hashicorp signing key to a new keyring.

wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

Enter fullscreen mode Exit fullscreen mode

4.) Verify the key's fingerprint

gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
Enter fullscreen mode Exit fullscreen mode

5.) Add hashicop repository to your machine list of repositories allowing you to have access to softwares in the hashicorp online repository.

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
Enter fullscreen mode Exit fullscreen mode

6.) Install terraform

sudo apt update && sudo apt install terraform

Enter fullscreen mode Exit fullscreen mode

7.) Verify if terraform is installed

terraform --help
Enter fullscreen mode Exit fullscreen mode

8.) Login to your AWS user account
In this tutorial I am logged into a IAM user with admin permissions, I strongly recommend doing the same thing to avoid creating resources with the root account. After login, go to the IAM Service on the console, click on the security credentials and generate new access keys

User credetials

Finally we with add the user credentials to the .bashrc file allowing the variables to be available globally on the machine
or we provide the user credentials for each project

9.) Run terraform init

Conclusion

Now that you have learnt how to link AWS user account Terrafrom you are ready to create resources and infrastructures using Terraform. You should however note that when linking AWS user account to Terraform locally for each project you should ensure not to push your user credentials to an online public website like GitHub.

馃挅 馃挭 馃檯 馃毄
tbello
Oluwatomisin Bello

Posted on February 5, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related