AWS

Install Terraform on EC2-Ubuntu Instance

terraform

What is Terraform?

Terraform is an infrastructure as a code tool that lets you build, change, and version cloud and on-prem resources safely and efficiently.

How does Terraform work?

Terraform creates and manages resources on cloud platforms and other services through its application programming interfaces (APIs). Providers enable Terraform to work with virtually any platform or service with an accessible API.

Install Terraform in Ubuntu EC2 Instance

Log in to the Amazon management console, open EC2 Dashboard, click on the Launch Instance drop-down list, and click on Launch instance:

Once the Launch an instance window opens, provide the name of your EC2 Instance:

Once the Launch an instance window opens, provide the name of your EC2 Instance:

Select an already existing key pair or create a new key pair. In my case I will create a new key pair:

A new window will open, enter the Key pair name and click on Create key pair.

Once you click on Create key pair the new key pair will be downloaded to your local machine which will be used later to ssh into the ubuntu machine.

Now under Network Settings, Create a new Security group and for the time being allow ssh traffic, HTTPS, and HTTP from anywhere (later on we can modify the rules)

Leave the rest of the options as default and click on the Launch instance button:

On the screen you can see a success message after the successful creation of the EC2 instance, click on Connect to instance button:

Now connect to instance wizard will open, go to SSH client tab and copy the provided chmod and SSH command:

Open the Command Prompt or PowerShell in your local machine and paste the following two commands:

After Successful login, Type this update command:

$ sudo apt-get update

Now we need to install the gnupg, software-properties-common, and curl packages. You will use these packages to verify HashiCorp’s GPG signature and install HashiCorp’s Debian package repository.

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

Install the HashiCorp GPG key.

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

Verify the key’s fingerprint. The gpg command will report the key fingerprint:

$ gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint

Add the official HashiCorp repository to your system

Now update your system.

Now is the time to Install Terraform from the new repository.

$ sudo apt-get install terraform

Once the installation process completes, check its version using the command:

$ terraform -v

In the output above, it is clear that the installation of terraform was successful as it is showing an installed version.

Type this command to initialize the working directory of terraform:

$ terraform init

In the output above, it is visible that the working directory is initialized and does not have any configuration file now, you are ready to use your Terraform for configurations now.

Also read Kubernetes Best Practices to Know

AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

View all posts by AmritMatti →

Leave a Reply

Your email address will not be published. Required fields are marked *