How to Install Terraform on Amazon Linux 2

In this article we are going to cover How to Install Terraform on Amazon Linux by downloading Zip archive, Install Terraform on Amazon Linux using YUM Repository and Uninstall terraform from Amazon Linux

Prerequisites

  • Amazon Linux with minimal Installation
  • SSH access with sudo privileges

Update the system packages

sudo yum update

Install the wget and unzip package to download and extract terraform setup if not already installed

sudo yum install wget unzip -y

How to Install Terraform on Amazon Linux by downloading Zip archive

First download the latest terraform version setup from Terraform Official Site using wget.

wget https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip

Output:

 https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip
Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.153.183, 2a04:4e42:24::439
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.153.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 33783879 (32M) [application/zip]
Saving to: ‘terraform_0.14.7_linux_amd64.zip’

100%[=============================================================================================>] 33,783,879   113MB/s   in 0.3s

2021-03-13 03:57:29 (113 MB/s) - ‘terraform_0.14.7_linux_amd64.zip’ saved [33783879/33783879]

Extract the downloaded setup using unzip

sudo unzip terraform_0.14.7_linux_amd64.zip

Output:

Archive:  terraform_0.14.7_linux_amd64.zip
  inflating: terraform

Move the extracted setup to /usr/local/bin directory

sudo mv terraform /usr/bin/

Lets verify Terraform version on Amazon Linux using below command

terraform -v

Output:

Terraform v0.14.7

Uninstall terraform from Amazon Linux, remove terrform from /usr/bin or /usr/local/bin directory

sudo rm -rf /usr/bin/terraform

OR

sudo rm -rf /usr/local/bin/terraform

Install Terraform on Amazon Linux using YUM Repository

Install yum-config-manager to Amazon Linux repositories.

sudo yum install -y yum-utils

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                      | 3.7 kB  00:00:00
Package yum-utils-1.1.31-46.amzn2.0.1.noarch already installed and latest version

Add the official HashiCorp Linux repository in yum-config-manager.

sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
adding repo from: https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
grabbing file https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo to /etc/yum.repos.d/hashicorp.repo
repo saved to /etc/yum.repos.d/hashicorp.repo

Install Terraform on Amazon Linux

sudo yum -y install terraform

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                      | 3.7 kB  00:00:00
hashicorp                                                                                                       | 1.4 kB  00:00:00
hashicorp/2/x86_64/primary                                                                                      |  39 kB  00:00:00
hashicorp                                                                                                                      257/257
Resolving Dependencies
--> Running transaction check
---> Package terraform.x86_64 0:0.14.8-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
 Package                          Arch                          Version                         Repository                        Size
=======================================================================================================================================
Installing:
 terraform                        x86_64                        0.14.8-1                        hashicorp                         26 M

Transaction Summary
=======================================================================================================================================
Install  1 Package

Total download size: 26 M
Installed size: 79 M
Downloading packages:
warning: /var/cache/yum/x86_64/2/hashicorp/packages/terraform-0.14.8-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a3219f7b: NOKEY
Public key for terraform-0.14.8-1.x86_64.rpm is not installed
terraform-0.14.8-1.x86_64.rpm                                                                                   |  26 MB  00:00:03
Retrieving key from https://rpm.releases.hashicorp.com/gpg
Importing GPG key 0xA3219F7B:
 Userid     : "HashiCorp Security (HashiCorp Package Signing) <[email protected]>"
 Fingerprint: e8a0 32e0 94d8 eb4e a189 d270 da41 8c88 a321 9f7b
 From       : https://rpm.releases.hashicorp.com/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : terraform-0.14.8-1.x86_64                                                                                           1/1
  Verifying  : terraform-0.14.8-1.x86_64                                                                                           1/1

Installed:
  terraform.x86_64 0:0.14.8-1

Complete!

To check Terraform version on Amazon Linux using command

terraform -v

Output:

Terraform v0.14.8

Lets check Terraform commands

terraform -help

Output:

Usage: terraform [global options] <subcommand> [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init          Prepare your working directory for other commands
  validate      Check whether the configuration is valid
  plan          Show changes required by the current configuration
  apply         Create or update infrastructure
  destroy       Destroy previously-created infrastructure

All other commands:
  console       Try Terraform expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote Terraform modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a Terraform resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current Terraform version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.

To Uninstall Terraform from Amazon Linux using YUM

sudo yum -y remove terraform

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package terraform.x86_64 0:0.14.8-1 will be erased
--> Finished Dependency Resolution
amzn2-core/2/x86_64                                                                                             | 3.7 kB  00:00:00

Dependencies Resolved

=======================================================================================================================================
 Package                         Arch                         Version                           Repository                        Size
=======================================================================================================================================
Removing:
 terraform                       x86_64                       0.14.8-1                          @hashicorp                        79 M

Transaction Summary
=======================================================================================================================================
Remove  1 Package

Installed size: 79 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : terraform-0.14.8-1.x86_64                                                                                           1/1
  Verifying  : terraform-0.14.8-1.x86_64                                                                                           1/1

Removed:
  terraform.x86_64 0:0.14.8-1

Complete!

Conclusion:

We have covered How to Install Terraform on Amazon Linux by downloading Zip archive, Install Terraform on Amazon Linux using YUM Repository and Uninstall terraform from Amazon Linux

Related Articles:

How to Install Azure CLI on Windows

About DevOps Hint

DevOps Hint Founded in 2020 Community Site where you can find about How to Guides, Articles and Troubleshooting Tips for DevOps, SRE, Sysadmins and Developers.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link