Steps to Install Terraform on Amazon Linux

In this Terraform Tutorials, we will explain the Steps to Install Terraform on Amazon Linux.

Steps to Install Terraform on Amazon Linux

Prerequisite to Install Terraform on Amazon Linux:

  • You must have Installed Amazon Linux Operating System on VM/Server.
  • SSH access with sudo / root permission
  • Internet access required to download the Terraform package.

Step 1: Download prerequisite to install Terraform

sudo yum install wget unzip

Ignore if it is already installed

Step 2: Download the Terraform on Amazon Linux

Method 1: Download Terraform with wget command.

[ec2-user@amzn1 ~]$ sudo wget https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip
--2020-02-29 12:24:10--  https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip
... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16018372 (15M) [application/zip]
Saving to: ‘terraform_0.12.2_linux_amd64.zip.1’

terraform_0.12.2_linux_amd64.zip. 100%[=============================================================>]  15.28M  --.-KB/s    in 0.1s

2020-02-29 12:24:10 (106 MB/s) - ‘terraform_0.12.2_linux_amd64.zip.1’ saved [16018372/16018372]

[ec2-user@amzn1 ~]$

Method 2: Download Terraform with curl command.

[ec2-user@amzn1 ~]$ curl -O https://releases.hashicorp.com/terraform/0.12.2/terraform_0.12.2_linux_amd64.zip

Step 3: Extract the downloaded terraform zip file

[ec2-user@amzn1 ~]$ sudo unzip ./terraform_0.12.2_linux_amd64.zip -d /usr/local/bin
Archive:  ./terraform_0.12.2_linux_amd64.zip
  inflating: /usr/local/bin/terraform
[ec2-user@amzn1 ~]$

Step 4: Command to Verify Terraform Version

[ec2-user@amzn1 ~]$ terraform -v

Terraform v0.12.2

[ec2-user@amzn1 ~]$
At the time this article was written, the latest version is Terraform v0.12.2. For a later version or a 32-bit version, please download from the official Terraform download page

Step 5: Terraform help command

Sample Output:

[ec2-user@amzn1 ~]$ terraform -help
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you are just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure
env Workspace management
fmt Rewrites config files to canonical format
get Download and install modules for the configuration
graph Create a visual graph of Terraform resources
import Import existing infrastructure into Terraform
init Initialize a Terraform working directory
output Read an output from a state file
plan Generate and show an execution plan
providers Prints a tree of the providers used in the configuration
refresh Update local state file against real resources
show Inspect Terraform state or plan
taint Manually mark a resource for recreation
untaint Manually unmark a resource as tainted
validate Validates the Terraform files
version Prints the Terraform version
workspace Workspace management

Similarly, you can add “–help” flag to any of the terraform command to get more information.

Sample output:

[ec2-user@amzn1 ~]$ terraform --help plan

Usage: terraform plan [options] [DIR]

Generates an execution plan for Terraform.

This execution plan can be reviewed prior to running apply to get a
sense for what Terraform will do. Optionally, the plan can be saved to
a Terraform plan file, and apply can take this plan file to execute
this plan exactly.

Options:

-destroy If set, a plan will be generated to destroy all resources
managed by the given configuration and state.

-detailed-exitcode Return detailed exit codes when the command exits. This
will change the meaning of exit codes to:
0 - Succeeded, diff is empty (no changes)
1 - Errored
2 - Succeeded, there is a diff

-input=true Ask for input for variables if not directly set.

-lock=true Lock the state file when locking is supported.

-lock-timeout=0s Duration to retry a state lock.

-no-color If specified, output will not contain any color.

-out=path Write a plan file to the given path. This can be used as
input to the "apply" command.

-parallelism=n Limit the number of concurrent operations. Defaults to 10.

-refresh=true Update state prior to checking for differences.

-state=statefile Path to a Terraform state file to use to look
up Terraform-managed resources. By default it will
use the state "terraform.tfstate" if it exists.

-target=resource Resource to target. Operation will be limited to this
resource and its dependencies. This flag can be used
multiple times.

-var "foo=bar" Set a variable in the Terraform configuration. This
flag can be set multiple times.

-var-file=foo Set variables in the Terraform configuration from
a file. If "terraform.tfvars" or any ".auto.tfvars"
files are present, they will be automatically loaded.

This is the end of the tutorial, we explain the steps to install Terraform on Amazon Linux.

If you are done with setup terraform then check out the blog on Setup AWS VPC Peering with Terraform code.


Thanks for reading these articles, You’ll also like these articles.

Docker Engine Architecture and Stages of Containerization

TOP 12 Cloud based Software as a Service

RUNDECK TUTORIALS FOR AUTOMATION

How to Install and Configure Cacti on Ubuntu 18 LTS